<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>python基本语法 | manor blog</title>
  
    <meta name="keywords" content=" python ">
  
  <meta name="description" content="python基本语法 | manor blog">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="description" content="个人简介pgmanor，程序员一名。 喜欢研究技术，涉及GO、JAVA、微服务、大数据领域。目前主要从事微服务。 联系方式 QQ : 2307546059 (pgmanor) 邮箱 :pgmanor@qq.com">
<meta property="og:type" content="website">
<meta property="og:title" content="关于">
<meta property="og:url" content="https://pgmanor.gitee.io/blog/about/index.html">
<meta property="og:site_name" content="manor blog">
<meta property="og:description" content="个人简介pgmanor，程序员一名。 喜欢研究技术，涉及GO、JAVA、微服务、大数据领域。目前主要从事微服务。 联系方式 QQ : 2307546059 (pgmanor) 邮箱 :pgmanor@qq.com">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2020-12-30T16:00:00.000Z">
<meta property="article:modified_time" content="2020-12-15T14:30:19.631Z">
<meta property="article:author" content="pgmanor">
<meta property="article:tag" content="pgmanor">
<meta property="article:tag" content="blog">
<meta name="twitter:card" content="summary">


<link rel="icon" href="/blog/img/pgmanor_blog.svg">

<link href="/blog/css/style.css?v=1.0.1x" rel="stylesheet">

<link href="/blog/css/hl_theme/atom-light.css?v=1.0.1x" rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" rel="stylesheet">
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.1/js/fontawesome.min.js" rel="stylesheet">

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="/blog/js/jquery.autocomplete.min.js?v=1.0.1x" ></script>
<script src="/blog/js/titleTip.js?v=1.0.1x" ></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.3/highlight.min.js"></script>
<script>
    hljs.initHighlightingOnLoad();
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>



<script src="/blog/js/iconfont.js?v=1.0.1x" ></script>

<meta name="generator" content="Hexo 4.2.1"></head>
<div style="display: none">
  <input class="theme_disqus_on" value="false">
  <input class="theme_preload_comment" value="false">
  <input class="theme_blog_path" value="/blog">
  <input id="theme_highlight_on" value="true" />
  <input id="theme_code_copy" value="true" />
</div>




<body>
<aside class="nav">
    <div class="nav-left">
        <a href="/blog/" class="avatar_target">
    <img class="avatar" src="/blog/img/pgmanor_blog.svg" />
</a>
<div class="author">
    <span>pgmanor</span>
</div>

<div class="icon">
    
        
        <a title="github" href="https://gitee.com/pgmanor" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-github"></use>
                </svg>
            
        </a>
        
    
        
        <a title="csdn" href="https://blog.csdn.net/u011622109" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-csdn"></use>
                </svg>
            
        </a>
        
    
        
        <a title="email" href="mailto:pgmanor@qq.com" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-email"></use>
                </svg>
            
        </a>
        
    
        
        <a title="qq" href="http://wpa.qq.com/msgrd?v=3&uin=2307546059&site=qq&menu=yes" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-qq"></use>
                </svg>
            
        </a>
        
    
        
        <a title="kugou" href="https://www.kugou.com/" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-kugou"></use>
                </svg>
            
        </a>
        
    
        
        <a title="neteasemusic" href="https://music.163.com/" target="_blank">
            
                <svg class="iconfont-svg" aria-hidden="true">
                    <use xlink:href="#icon-neteasemusic"></use>
                </svg>
            
        </a>
        
    
</div>



<a class="more-menus">更多菜单</a>


<ul>
    <li><div class="all active">全部文章<small>(129)</small></div></li>
    
        
            
            <li><div data-rel="博客"><i class="fold iconfont icon-right"></i>博客<small>(108)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="B---大数据">B---大数据<small>(4)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="C-----并发">C-----并发<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="D--数据库">D--数据库<small>(16)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="D-devops">D-devops<small>(5)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="F-----架构">F-----架构<small>(10)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="I-----面试">I-----面试<small>(2)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="J-----java">J-----java<small>(14)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="M--微服务">M--微服务<small>(6)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="P-python">P-python<small>(9)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="T-----工具">T-----工具<small>(26)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="T-----测试">T-----测试<small>(6)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="W-----前端">W-----前端<small>(4)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="W-window">W-window<small>(3)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="微服务">微服务<small>(2)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="农场"><i class="fold iconfont icon-right"></i>农场<small>(10)</small></div>
                
                    <ul class="sub hide">
                        
                        <li><div data-rel="微服务">微服务<small>(1)</small></div>
                            
                        </li>
                            
                        <li><div data-rel="算法">算法<small>(8)</small></div>
                            
                        </li>
                            
                    </ul>
                
            </li>
            
        
    
        
            
            <li><div data-rel="项目">项目<small>(9)</small></div>
                
            </li>
            
        
    
        
            
            <li><div data-rel="加密">加密<small>(2)</small></div>
                
            </li>
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
        
            
        
    
</ul>
<div class="left-bottom">
    <div class="menus">
    
    
    
    <a class="dynamic-menu " target="_blank"  href="https://www.iworkh.com/">iworkh</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://gitee.com/pgmanor">gitee</a>
    
    </div>
    <div><a class="about  hasFriend  site_url"  href="/blog/about">关于</a><a style="width: 50%"  class="friends">友链</a></div>
</div>
<input type="hidden" id="iworkh_site_posts_number" value="129">
<input type="hidden" id="iworkh_site_word_count" value="273k">
<div style="display: none">
    <span id="busuanzi_value_site_uv"></span>
    <span id="busuanzi_value_site_pv"></span>
</div>

    </div>
    <div class="nav-right">
        <div class="friends-area">
    <div class="friends-title">
        友情链接
        <i class="back-title-list"></i>
    </div>
    <div class="friends-content">
        <ul>
            
            <li><a target="_blank" href="https://www.iworkh.com">iworkh</a></li>
            
            <li><a target="_blank" href="https://www.iworkh.com/download/share/">下载地址</a></li>
            
            <li><a target="_blank" href="http://yelog.org/">叶落阁</a></li>
            
        </ul>
    </div>
</div>
        <div class="title-list">
    <form onkeydown="if(event.keyCode === 13){return false;}">
        <input id="local-search-input" class="search" type="text" placeholder="in: 开头全文搜索" />
        <i class="cross"></i>
        <span>
            <label for="tagswitch">T:</label>
            <input id="tagswitch" type="checkbox" style="display: none" />
            <i id="tagsWitchIcon"></i>
        </span>
    </form>
    <div class="tags-list">
    
    <li class="article-tag-list-item">
        <a class="color4">AQS</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">attr</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">aysnc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">beanmap</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">bigdecimal</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">blog</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">chrome</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">dict</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">dll</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">doc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">docker</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">domain</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">elementadmin</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">es</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">excel</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">farm</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">fastjson</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">func</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">git</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">github</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">guide</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">hadoop</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">hexo</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">idea</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">initialzr</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">jackson</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">java</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">jboss</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">jdni</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">jetbrains</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">jfinalshell</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">joplin</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">JPA</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">junit</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">jupyter</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">keepavlie</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">kill</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">linux</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">LocalDate</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">lock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">markdown</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">maven</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">message</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">mock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">mq</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">mycat</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">mysql</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">nginx</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">notebook</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">postman</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">powermock</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">python</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">redis</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">rest</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">sharding-jdbc</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">spark</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">springboot</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color2">testng</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">tornado</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color1">track</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">transactional</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">uuid</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">vuepress</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">web</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">windows</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">zookeeper</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">分库分表</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">分页</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">加密</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">启动</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">工具</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">并发</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">序列化</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">微服务</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">性能分析</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">手册</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color4">有道云</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">模板</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color5">百度云盘</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">算法</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">面试</a>
    </li>
    
    <li class="article-tag-list-item">
        <a class="color3">项目</a>
    </li>
    
    <div class="clearfix"></div>
</div>

    
    <div id="local-search-result">

    </div>
    
    <nav id="title-list-nav">
        
        <a id="top" class="农场 "
           href="/blog/2020/12/31/farm-manual-summary/"
           data-tag="手册,farm"
           data-author="pgmanor" >
            <span class="post-title" title="手册汇总">手册汇总</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a id="top" class="农场 微服务 "
           href="/blog/2020/12/31/farm-spring-boot-all-resources/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="Spring Boot全网优质教程汇总">Spring Boot全网优质教程汇总</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a id="top" class="加密 "
           href="/blog/2021/01/10/secret-farm-mysql/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql密钥">mysql密钥</span>
            <span class="post-date" title="2021-01-10 00:00:00">2021/01/10</span>
        </a>
        
        <a id="top" class="加密 "
           href="/blog/2020/12/31/secret-baidu-pandisk-share/"
           data-tag="百度云盘"
           data-author="pgmanor" >
            <span class="post-title" title="百度云盘分享链接">百度云盘分享链接</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a id="top" class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-jetbrains-idea/"
           data-tag="idea"
           data-author="pgmanor" >
            <span class="post-title" title="idea使用技巧">idea使用技巧</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a id="top" class="博客 T-----工具 "
           href="/blog/2021/03/14/blog-tool-online/"
           data-tag="blog"
           data-author="pgmanor" >
            <span class="post-title" title="常用在线工具">常用在线工具</span>
            <span class="post-date" title="2021-03-14 00:00:00">2021/03/14</span>
        </a>
        
        <a id="top" class="博客 W-----前端 "
           href="/blog/2020/12/31/blog-web/"
           data-tag="web"
           data-author="pgmanor" >
            <span class="post-title" title="前端常用工具">前端常用工具</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/09/12/project-guide-http/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="模拟http请求">模拟http请求</span>
            <span class="post-date" title="2021-09-12 00:00:00">2021/09/12</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/09/12/blog-tool-chrome-disable-cros/"
           data-tag="chrome"
           data-author="pgmanor" >
            <span class="post-title" title="禁用Chrome跨域">禁用Chrome跨域</span>
            <span class="post-date" title="2021-09-12 00:00:00">2021/09/12</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/09/04/project-guide-download-excel/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="vue和hutool工具实现excel下载">vue和hutool工具实现excel下载</span>
            <span class="post-date" title="2021-09-04 00:00:00">2021/09/04</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/09/04/project-guide-param-pass-array/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="axios参数传数组">axios参数传数组</span>
            <span class="post-date" title="2021-09-04 00:00:00">2021/09/04</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/08/15/blog-mysql-backup-cron/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="cron定时器">cron定时器</span>
            <span class="post-date" title="2021-08-15 00:00:00">2021/08/15</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/08/14/blog-mysql-backup-xtrabackup/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql备份-xtrabackup">mysql备份-xtrabackup</span>
            <span class="post-date" title="2021-08-14 00:00:00">2021/08/14</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/08/14/blog-mysql-backup-xtrabackup-scripts/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql备份-xtrabackup-脚本">mysql备份-xtrabackup-脚本</span>
            <span class="post-date" title="2021-08-14 00:00:00">2021/08/14</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/08/08/project-guide-devops-slowquery/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="SQL慢查询">SQL慢查询</span>
            <span class="post-date" title="2021-08-08 00:00:00">2021/08/08</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/08/08/blog-mysql-backup-summary/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql备份">mysql备份</span>
            <span class="post-date" title="2021-08-08 00:00:00">2021/08/08</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/08/08/project-guide-springboot-upgrade/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="springboot升级到2.5.x遇到的问题">springboot升级到2.5.x遇到的问题</span>
            <span class="post-date" title="2021-08-08 00:00:00">2021/08/08</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2021/08/07/blog-fw-es-install/"
           data-tag="es"
           data-author="pgmanor" >
            <span class="post-title" title="ElasticSearch安装和使用">ElasticSearch安装和使用</span>
            <span class="post-date" title="2021-08-07 00:00:00">2021/08/07</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/08/07/project-guide-log-analysis/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="日志分析">日志分析</span>
            <span class="post-date" title="2021-08-07 00:00:00">2021/08/07</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/08/07/project-guide-devops-monitor/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="运维监控">运维监控</span>
            <span class="post-date" title="2021-08-07 00:00:00">2021/08/07</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/08/01/blog-tool-postman/"
           data-tag="postman"
           data-author="pgmanor" >
            <span class="post-title" title="postman工具使用">postman工具使用</span>
            <span class="post-date" title="2021-08-01 00:00:00">2021/08/01</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/08/01/blog-tool-bug-track/"
           data-tag="track"
           data-author="pgmanor" >
            <span class="post-title" title="bug跟踪工具">bug跟踪工具</span>
            <span class="post-date" title="2021-08-01 00:00:00">2021/08/01</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/08/01/blog-java-kill/"
           data-tag="kill"
           data-author="pgmanor" >
            <span class="post-title" title="java项目如何优雅关闭程序">java项目如何优雅关闭程序</span>
            <span class="post-date" title="2021-08-01 00:00:00">2021/08/01</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2021/07/25/blog-spring-boot-logback/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="springboot logback多环境">springboot logback多环境</span>
            <span class="post-date" title="2021-07-25 00:00:00">2021/07/25</span>
        </a>
        
        <a  class="博客 W-----前端 "
           href="/blog/2021/06/18/blog-vue-element-admin-keepalive/"
           data-tag="keepavlie"
           data-author="pgmanor" >
            <span class="post-title" title="vue中keep alive失效">vue中keep alive失效</span>
            <span class="post-date" title="2021-06-18 00:00:00">2021/06/18</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/06/14/blog-java-start/"
           data-tag="启动"
           data-author="pgmanor" >
            <span class="post-title" title="java启动方式">java启动方式</span>
            <span class="post-date" title="2021-06-14 00:00:00">2021/06/14</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/05/31/project-guide-vue-component/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="vue封装组件">vue封装组件</span>
            <span class="post-date" title="2021-05-31 00:00:00">2021/05/31</span>
        </a>
        
        <a  class="项目 "
           href="/blog/2021/05/09/project-guide-vue-full-calendar/"
           data-tag="项目,guide"
           data-author="pgmanor" >
            <span class="post-title" title="vue-full-calendar日历">vue-full-calendar日历</span>
            <span class="post-date" title="2021-05-09 00:00:00">2021/05/09</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2021/05/04/blog-redis-local/"
           data-tag="redis"
           data-author="pgmanor" >
            <span class="post-title" title="嵌入redis和可视化界面">嵌入redis和可视化界面</span>
            <span class="post-date" title="2021-05-04 22:48:35">2021/05/04</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/03/14/blog-tool-doc/"
           data-tag="doc"
           data-author="pgmanor" >
            <span class="post-title" title="文档工具">文档工具</span>
            <span class="post-date" title="2021-03-14 00:00:00">2021/03/14</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/03/14/blog-jpa-anno-generatedValue/"
           data-tag="JPA"
           data-author="pgmanor" >
            <span class="post-title" title="JPA注解@GeneratedValue">JPA注解@GeneratedValue</span>
            <span class="post-date" title="2021-03-14 00:00:00">2021/03/14</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/03/14/blog-tool-chrome/"
           data-tag="chrome"
           data-author="pgmanor" >
            <span class="post-title" title="Chrome调试技巧">Chrome调试技巧</span>
            <span class="post-date" title="2021-03-14 00:00:00">2021/03/14</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/03/14/blog-vuepress-fulltext-search/"
           data-tag="vuepress"
           data-author="pgmanor" >
            <span class="post-title" title="vuepress支持全文搜索">vuepress支持全文搜索</span>
            <span class="post-date" title="2021-03-14 00:00:00">2021/03/14</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2021/03/07/blog-redis-type-string-sds/"
           data-tag="redis"
           data-author="pgmanor" >
            <span class="post-title" title="Redis为什么将String设计成SDS">Redis为什么将String设计成SDS</span>
            <span class="post-date" title="2021-03-07 00:00:00">2021/03/07</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2021/03/07/blog-redis-fast/"
           data-tag="redis"
           data-author="pgmanor" >
            <span class="post-title" title="Redis为什么这么快">Redis为什么这么快</span>
            <span class="post-date" title="2021-03-07 00:00:00">2021/03/07</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2021/03/07/blog-redis-type-six/"
           data-tag="redis"
           data-author="pgmanor" >
            <span class="post-title" title="Redis的6大数据类型">Redis的6大数据类型</span>
            <span class="post-date" title="2021-03-07 00:00:00">2021/03/07</span>
        </a>
        
        <a  class="博客 微服务 "
           href="/blog/2021/03/06/blog-spring-boot-h2/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="springboot整合h2">springboot整合h2</span>
            <span class="post-date" title="2021-03-06 00:00:00">2021/03/06</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/02/28/blog-java-md5/"
           data-tag="uuid"
           data-author="pgmanor" >
            <span class="post-title" title="MD5加密">MD5加密</span>
            <span class="post-date" title="2021-02-28 00:00:00">2021/02/28</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/02/28/blog-java-uuid/"
           data-tag="uuid"
           data-author="pgmanor" >
            <span class="post-title" title="UUID">UUID</span>
            <span class="post-date" title="2021-02-28 00:00:00">2021/02/28</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/02/28/blog-java-base64/"
           data-tag="uuid"
           data-author="pgmanor" >
            <span class="post-title" title="base64加解密">base64加解密</span>
            <span class="post-date" title="2021-02-28 00:00:00">2021/02/28</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2021/02/27/blog-java-new8-date-opertaion.md/"
           data-tag="LocalDate"
           data-author="pgmanor" >
            <span class="post-title" title="java8日期操作">java8日期操作</span>
            <span class="post-date" title="2021-02-27 00:00:00">2021/02/27</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/01/24/blog-jpa-entity-manager/"
           data-tag="JPA"
           data-author="pgmanor" >
            <span class="post-title" title="JPA之EntityManager">JPA之EntityManager</span>
            <span class="post-date" title="2021-01-24 00:00:00">2021/01/24</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2021/01/24/blog-jpa-relationship/"
           data-tag="JPA"
           data-author="pgmanor" >
            <span class="post-title" title="JPA表与表关系映射">JPA表与表关系映射</span>
            <span class="post-date" title="2021-01-24 00:00:00">2021/01/24</span>
        </a>
        
        <a  class="博客 W-----前端 "
           href="/blog/2021/01/24/blog-web-CodeMirror/"
           data-tag="web"
           data-author="pgmanor" >
            <span class="post-title" title="CodeMirror">CodeMirror</span>
            <span class="post-date" title="2021-01-24 00:00:00">2021/01/24</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/01/10/blog-vuepress-theme-password/"
           data-tag="vuepress"
           data-author="pgmanor" >
            <span class="post-title" title="vuepress-theme-reco源码密钥修改">vuepress-theme-reco源码密钥修改</span>
            <span class="post-date" title="2021-01-10 00:00:00">2021/01/10</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/01/03/blog-tool-encryption/"
           data-tag="加密"
           data-author="pgmanor" >
            <span class="post-title" title="在线加密工具">在线加密工具</span>
            <span class="post-date" title="2021-01-03 10:08:09">2021/01/03</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/01/02/blog-tool-jboss-password/"
           data-tag="jboss"
           data-author="pgmanor" >
            <span class="post-title" title="jboss数据库密码加解密">jboss数据库密码加解密</span>
            <span class="post-date" title="2021-01-02 00:00:00">2021/01/02</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2021/01/02/blog-tool-excel-hidden-col/"
           data-tag="excel"
           data-author="pgmanor" >
            <span class="post-title" title="excel隐藏空白列">excel隐藏空白列</span>
            <span class="post-date" title="2021-01-02 00:00:00">2021/01/02</span>
        </a>
        
        <a  class="博客 微服务 "
           href="/blog/2021/01/02/blog-spring-boot-run-withparam-windows/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="springboot项目多环境运行报错 windows">springboot项目多环境运行报错 windows</span>
            <span class="post-date" title="2021-01-02 00:00:00">2021/01/02</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-sort/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法8-排序">数据结构和算法8-排序</span>
            <span class="post-date" title="2020-12-31 08:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-search/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法7-搜索">数据结构和算法7-搜索</span>
            <span class="post-date" title="2020-12-31 07:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-graph/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法6-非线性-图">数据结构和算法6-非线性-图</span>
            <span class="post-date" title="2020-12-31 06:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-tree/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法5-非线性-树">数据结构和算法5-非线性-树</span>
            <span class="post-date" title="2020-12-31 05:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-linear-queue/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法4-线性-队列">数据结构和算法4-线性-队列</span>
            <span class="post-date" title="2020-12-31 04:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-linear-stack/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法3-线性-栈">数据结构和算法3-线性-栈</span>
            <span class="post-date" title="2020-12-31 03:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-linear-list/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法2-线性-链">数据结构和算法2-线性-链</span>
            <span class="post-date" title="2020-12-31 02:00:00">2020/12/31</span>
        </a>
        
        <a  class="农场 算法 "
           href="/blog/2020/12/31/farm-data-structures-algorithms-info/"
           data-tag="算法"
           data-author="pgmanor" >
            <span class="post-title" title="数据结构和算法1-介绍">数据结构和算法1-介绍</span>
            <span class="post-date" title="2020-12-31 01:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D-devops "
           href="/blog/2020/12/31/blog-devops-linux-jfinalshell/"
           data-tag="jfinalshell"
           data-author="pgmanor" >
            <span class="post-title" title="linux连接工具jfinalshell">linux连接工具jfinalshell</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python-tool-buildin-func/"
           data-tag="func"
           data-author="pgmanor" >
            <span class="post-title" title="👍python内置函数">👍python内置函数</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-jpa-query-multi-param/"
           data-tag="JPA"
           data-author="pgmanor" >
            <span class="post-title" title="JPA多条件查询">JPA多条件查询</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-jpa-query/"
           data-tag="JPA"
           data-author="pgmanor" >
            <span class="post-title" title="JPA自定义sql">JPA自定义sql</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2020/12/31/blog-fw-mq-message-missing/"
           data-tag="mq,message"
           data-author="pgmanor" >
            <span class="post-title" title="MQ如何保证消息不丢失?">MQ如何保证消息不丢失?</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 B---大数据 "
           href="/blog/2020/12/31/blog-hadoop-install-windows/"
           data-tag="hadoop"
           data-author="pgmanor" >
            <span class="post-title" title="hadoop开发环境搭建">hadoop开发环境搭建</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-mysql-lock-unlock-table/"
           data-tag="lock"
           data-author="pgmanor" >
            <span class="post-title" title="mysql数据库锁查询和释放">mysql数据库锁查询和释放</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-ai-python-spark-env/"
           data-tag="spark"
           data-author="pgmanor" >
            <span class="post-title" title="python spark开发环境搭建">python spark开发环境搭建</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-mysql-windows-zip-install/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql zip在windows上安装">mysql zip在windows上安装</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python_install/"
           data-tag="python"
           data-author="pgmanor" >
            <span class="post-title" title="python环境安装">python环境安装</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D-devops "
           href="/blog/2020/12/31/blog-devops-docker-introduction/"
           data-tag="docker"
           data-author="pgmanor" >
            <span class="post-title" title="👍docker入门看这一篇就够了">👍docker入门看这一篇就够了</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 I-----面试 "
           href="/blog/2020/12/31/blog-interview-company/"
           data-tag="面试"
           data-author="pgmanor" >
            <span class="post-title" title="IT互联网公司名单">IT互联网公司名单</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-base-domain/"
           data-tag="domain"
           data-author="pgmanor" >
            <span class="post-title" title="VO DTO DO PO你都了解吗?">VO DTO DO PO你都了解吗?</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-base-serializable/"
           data-tag="序列化"
           data-author="pgmanor" >
            <span class="post-title" title="java序列化">java序列化</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-hexo-theme-math/"
           data-tag="hexo"
           data-author="pgmanor" >
            <span class="post-title" title="hexo主题支持MathJax">hexo主题支持MathJax</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 C-----并发 "
           href="/blog/2020/12/31/blog-java-concurrent-aqs/"
           data-tag="AQS,并发"
           data-author="pgmanor" >
            <span class="post-title" title="java并发AQS">java并发AQS</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-java-dao-sharding-db/"
           data-tag="分库分表"
           data-author="pgmanor" >
            <span class="post-title" title="分库分表中间件-开源产品">分库分表中间件-开源产品</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 B---大数据 "
           href="/blog/2020/12/31/blog-spark-install-windows/"
           data-tag="spark"
           data-author="pgmanor" >
            <span class="post-title" title="spark开发环境搭建">spark开发环境搭建</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-jetbrains-crack/"
           data-tag="idea,jetbrains"
           data-author="pgmanor" >
            <span class="post-title" title="jetbrains全家桶破解">jetbrains全家桶破解</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2020/12/31/blog-spring-boot-multi-profiles/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="springboot多环境配置打包">springboot多环境配置打包</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-markdown-math-express/"
           data-tag="markdown"
           data-author="pgmanor" >
            <span class="post-title" title="markdown数学公式">markdown数学公式</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 I-----面试 "
           href="/blog/2020/12/31/blog-interview-java-question/"
           data-tag="面试"
           data-author="pgmanor" >
            <span class="post-title" title="java常见面试题">java常见面试题</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2020/12/31/blog-nginx-fast/"
           data-tag="nginx"
           data-author="pgmanor" >
            <span class="post-title" title="nginx为何这么快?">nginx为何这么快?</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2020/12/31/spring-initialzr/"
           data-tag="工具,initialzr"
           data-author="pgmanor" >
            <span class="post-title" title="spring initialzr环境编译发布">spring initialzr环境编译发布</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2020/12/31/blog-redis-memory-eliminate/"
           data-tag="redis"
           data-author="pgmanor" >
            <span class="post-title" title="Redis的内存淘汰策略">Redis的内存淘汰策略</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2020/12/31/blog-spring-pageable/"
           data-tag="分页"
           data-author="pgmanor" >
            <span class="post-title" title="vue+springboot分页交互">vue+springboot分页交互</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python_base/"
           data-tag="python"
           data-author="pgmanor" >
            <span class="post-title" title="python基本语法">python基本语法</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2020/12/31/blog-spring-transaction/"
           data-tag="transactional"
           data-author="pgmanor" >
            <span class="post-title" title="Transactional注解">Transactional注解</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/12/31/blog-test-ng/"
           data-tag="testng"
           data-author="pgmanor" >
            <span class="post-title" title="👍TestNG一篇足以">👍TestNG一篇足以</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/12/31/blog-test-mockito/"
           data-tag="mock"
           data-author="pgmanor" >
            <span class="post-title" title="👍mockito测试框架">👍mockito测试框架</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/12/31/blog-test-powermock/"
           data-tag="powermock"
           data-author="pgmanor" >
            <span class="post-title" title="powermock测试框架">powermock测试框架</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-blogs-all/"
           data-tag="blog"
           data-author="pgmanor" >
            <span class="post-title" title="优质博客和文章">优质博客和文章</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 W-window "
           href="/blog/2020/12/31/blog-tool-windows-dev-install/"
           data-tag="windows"
           data-author="pgmanor" >
            <span class="post-title" title="windows开发环境安装">windows开发环境安装</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-base-bigdecimal/"
           data-tag="bigdecimal"
           data-author="pgmanor" >
            <span class="post-title" title="BigDecimal正确使用了吗?">BigDecimal正确使用了吗?</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 W-----前端 "
           href="/blog/2020/12/31/blog-vue-element-admin/"
           data-tag="elementadmin"
           data-author="pgmanor" >
            <span class="post-title" title="vue element admin开发">vue element admin开发</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 M--微服务 "
           href="/blog/2020/12/31/blog-vue-springboot-package-publish/"
           data-tag="springboot"
           data-author="pgmanor" >
            <span class="post-title" title="vue+springboot打包发布">vue+springboot打包发布</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-java-dao-mycat/"
           data-tag="mycat"
           data-author="pgmanor" >
            <span class="post-title" title="分库分表中间件-MyCat">分库分表中间件-MyCat</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-connect-github/"
           data-tag="github"
           data-author="pgmanor" >
            <span class="post-title" title="github无法访问解决办法">github无法访问解决办法</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-install-windows/"
           data-tag="java"
           data-author="pgmanor" >
            <span class="post-title" title="jdk开发环境搭建">jdk开发环境搭建</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-ai-jupyter-notebook/"
           data-tag="jupyter"
           data-author="pgmanor" >
            <span class="post-title" title="jupyter notebook">jupyter notebook</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-chrome-plugin/"
           data-tag="chrome"
           data-author="pgmanor" >
            <span class="post-title" title="chrome插件">chrome插件</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-git-error-name-too-long/"
           data-tag="git"
           data-author="pgmanor" >
            <span class="post-title" title="git文件名太长">git文件名太长</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-git-setting/"
           data-tag="git"
           data-author="pgmanor" >
            <span class="post-title" title="git配置">git配置</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python_tornado_info/"
           data-tag="tornado"
           data-author="pgmanor" >
            <span class="post-title" title="👍Tornado入门这一篇足以">👍Tornado入门这一篇足以</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-maven/"
           data-tag="maven"
           data-author="pgmanor" >
            <span class="post-title" title="maven常用命令和配置">maven常用命令和配置</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-notebook-joplin/"
           data-tag="joplin"
           data-author="pgmanor" >
            <span class="post-title" title="joplin笔记">joplin笔记</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-notebook/"
           data-tag="notebook"
           data-author="pgmanor" >
            <span class="post-title" title="常见笔记软件">常见笔记软件</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2020/12/31/blog-fw-distributed-lock-redis-zk/"
           data-tag="lock,redis,zookeeper"
           data-author="pgmanor" >
            <span class="post-title" title="分布式锁用redis还是zk?">分布式锁用redis还是zk?</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-java-dao-shardingSphere/"
           data-tag="sharding-jdbc"
           data-author="pgmanor" >
            <span class="post-title" title="分库分表中间件-ShardingSphere">分库分表中间件-ShardingSphere</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/12/31/blog-test-rest-assured-in-action/"
           data-tag="rest"
           data-author="pgmanor" >
            <span class="post-title" title="rest-assured实战">rest-assured实战</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 F-----架构 "
           href="/blog/2020/12/31/blog-microservice-why/"
           data-tag="微服务"
           data-author="pgmanor" >
            <span class="post-title" title="一定要使用微服务？">一定要使用微服务？</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-tool-bean-map/"
           data-tag="beanmap"
           data-author="pgmanor" >
            <span class="post-title" title="工具类--bean和map互转">工具类--bean和map互转</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-mysql-common-sql/"
           data-tag="mysql"
           data-author="pgmanor" >
            <span class="post-title" title="mysql常用sql">mysql常用sql</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python-tool-buildin-attr/"
           data-tag="attr"
           data-author="pgmanor" >
            <span class="post-title" title="👍python内置属性(魔法方法)">👍python内置属性(魔法方法)</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-python-tool-obj-dict/"
           data-tag="dict"
           data-author="pgmanor" >
            <span class="post-title" title="python对象与dict互转">python对象与dict互转</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-tool-fastjson-bug/"
           data-tag="fastjson"
           data-author="pgmanor" >
            <span class="post-title" title="Fastjson远程代码高危漏洞">Fastjson远程代码高危漏洞</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 B---大数据 "
           href="/blog/2020/12/31/blog-spark-data-skew/"
           data-tag="spark"
           data-author="pgmanor" >
            <span class="post-title" title="spark数据倾斜及解决方案">spark数据倾斜及解决方案</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 B---大数据 "
           href="/blog/2020/12/31/blog-spark-version-3/"
           data-tag="spark"
           data-author="pgmanor" >
            <span class="post-title" title="spark3.0新特性">spark3.0新特性</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 W-window "
           href="/blog/2020/12/31/blog-tool-windows-cmd/"
           data-tag="windows"
           data-author="pgmanor" >
            <span class="post-title" title="windows常用命令和技巧">windows常用命令和技巧</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 W-window "
           href="/blog/2020/12/31/blog-tool-windows-less-dll/"
           data-tag="dll"
           data-author="pgmanor" >
            <span class="post-title" title="windows缺少dll">windows缺少dll</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/31/blog-tool-youdao-config-edit/"
           data-tag="有道云"
           data-author="pgmanor" >
            <span class="post-title" title="有道云配置修改">有道云配置修改</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 D--数据库 "
           href="/blog/2020/12/31/blog-java-jndi/"
           data-tag="jdni"
           data-author="pgmanor" >
            <span class="post-title" title="JNDI">JNDI</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-online-analysis/"
           data-tag="性能分析"
           data-author="pgmanor" >
            <span class="post-title" title="JAVA线上故障排查全套路">JAVA线上故障排查全套路</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 P-python "
           href="/blog/2020/12/31/blog-tornado-sync-to-async/"
           data-tag="aysnc,tornado"
           data-author="pgmanor" >
            <span class="post-title" title="tornado同步转异步">tornado同步转异步</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 J-----java "
           href="/blog/2020/12/31/blog-java-tool-jackson/"
           data-tag="jackson"
           data-author="pgmanor" >
            <span class="post-title" title="工具类--jackson">工具类--jackson</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/12/31/blog-rest-assured-wiki-info/"
           data-tag="rest"
           data-author="pgmanor" >
            <span class="post-title" title="rest-assured wiki翻译">rest-assured wiki翻译</span>
            <span class="post-date" title="2020-12-31 00:00:00">2020/12/31</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/30/blog-template/"
           data-tag="模板"
           data-author="pgmanor" >
            <span class="post-title" title="hexo博客自定义模板">hexo博客自定义模板</span>
            <span class="post-date" title="2020-12-30 00:00:00">2020/12/30</span>
        </a>
        
        <a  class="博客 T-----工具 "
           href="/blog/2020/12/27/blog-hexo-comments-valine/"
           data-tag="hexo"
           data-author="pgmanor" >
            <span class="post-title" title="hexo扩展评论valine">hexo扩展评论valine</span>
            <span class="post-date" title="2020-12-27 08:59:46">2020/12/27</span>
        </a>
        
        <a  class="博客 D-devops "
           href="/blog/2020/08/15/blog-devops-linux-shell-param/"
           data-tag="linux"
           data-author="pgmanor" >
            <span class="post-title" title="shell 脚本参数解析之getopt和getopts">shell 脚本参数解析之getopt和getopts</span>
            <span class="post-date" title="2020-08-15 00:00:00">2020/08/15</span>
        </a>
        
        <a  class="博客 T-----测试 "
           href="/blog/2020/08/08/blog-test-junit4v5/"
           data-tag="junit"
           data-author="pgmanor" >
            <span class="post-title" title="Junit4和Junit5差异">Junit4和Junit5差异</span>
            <span class="post-date" title="2020-08-08 00:00:00">2020/08/08</span>
        </a>
        
        <a  class="博客 D-devops "
           href="/blog/2020/08/01/blog-devops-linux-command/"
           data-tag="linux"
           data-author="pgmanor" >
            <span class="post-title" title="linux常用命令">linux常用命令</span>
            <span class="post-date" title="2020-08-01 00:00:00">2020/08/01</span>
        </a>
        
        <a  class="博客 D-devops "
           href="/blog/2020/08/01/blog-devops-linux-cmd-adv/"
           data-tag="linux"
           data-author="pgmanor" >
            <span class="post-title" title="linux几个高级命令">linux几个高级命令</span>
            <span class="post-date" title="2020-08-01 00:00:00">2020/08/01</span>
        </a>
        
    </nav>
</div>

    </div>
    <div class="hide-list">
        <div class="semicircle" data-title="切换全屏 快捷键 s">
            <div class="brackets first"><</div>
            <div class="brackets">&gt;</div>
        </div>
    </div>
</aside>
<div class="post">
    <div class="pjax">
        <article id="post-blog/blog-python_base" class="article article-type-post" itemscope itemprop="blogPost">
    
        <h1 class="article-title">python基本语法</h1>
    
    <div class="article-meta">
        
        
        <span class="author"><a>pgmanor</a></span>
        
        
        <span class="book">
            
                <a  data-rel="博客">博客</a>/
            
                <a  data-rel="P-python">P-python</a>
            
        </span>
        
        
        <span class="tag">
            
            <a class="color2">python</a>
            
        </span>
        
    </div>
    <div class="article-meta">
        
            发布时间 : <time class="date" title='最后更新: 2020-12-15 23:12:30'>2020-12-31 00:00</time>
        
    </div>
    <div class="article-meta">
        
        <span>字数:9.8k</span>
        
        
        <span id="busuanzi_container_page_pv">
            阅读 :<span id="busuanzi_value_page_pv">
                <span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </span>
        </span>
        
        
        <span class="top-comment" title="跳转至评论区">
            <a href="#comments">
                评论:<span class="count-comment">
                    <span class="spinner">
                      <div class="cube1"></div>
                      <div class="cube2"></div>
                    </span>
                </span>
            </a>
        </span>
        
    </div>
    
    <div class="toc-ref">
    
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#1-介绍"><span class="toc-text">1.介绍</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#2-数据结构"><span class="toc-text">2.数据结构</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#2-1-数字-num"><span class="toc-text">2-1.数字(num)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-2-布尔-bool-与逻辑"><span class="toc-text">2-2.布尔(bool)与逻辑</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-3-序列-sequence"><span class="toc-text">2-3.序列(sequence)</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#2-3-1-字符串-str"><span class="toc-text">2-3-1.字符串(str)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-3-2-列表-list"><span class="toc-text">2-3-2.列表(list)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#2-3-3-元组-tuple"><span class="toc-text">2-3-3.元组(tuple)</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-4-字典-dict"><span class="toc-text">2-4.字典(dict)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#2-5-集合-set"><span class="toc-text">2-5.集合(set)</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#3-基本语句"><span class="toc-text">3.基本语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#3-1-if语句与三元操作"><span class="toc-text">3-1.if语句与三元操作</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-2-for-语句"><span class="toc-text">3-2.for 语句</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-3-while-语句"><span class="toc-text">3-3.while 语句</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#3-4-列表解析"><span class="toc-text">3-4.列表解析</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#4-函数"><span class="toc-text">4.函数</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#4-1-函数定义与判断"><span class="toc-text">4-1.函数定义与判断</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-2-不定参函数"><span class="toc-text">4-2.不定参函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-3-zip-函数"><span class="toc-text">4-3.zip 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-4-lambda-函数"><span class="toc-text">4-4.lambda 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-5-map-函数"><span class="toc-text">4-5.map 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-6-filter-函数"><span class="toc-text">4-6.filter 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-8-reduce-函数"><span class="toc-text">4-8.reduce 函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#4-9-enumerate-函数"><span class="toc-text">4-9.enumerate 函数</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#5-装饰器：算子"><span class="toc-text">5.装饰器：算子</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#6-迭代器-itertools"><span class="toc-text">6.迭代器 [itertools]</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#6-1-迭代器"><span class="toc-text">6-1.迭代器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#6-2-生成器"><span class="toc-text">6-2.生成器</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#7-错误：try-语句"><span class="toc-text">7.错误：try() 语句</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#7-1-多个-except-块"><span class="toc-text">7-1.多个 except 块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-3-错误的捕获"><span class="toc-text">7-3.错误的捕获</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#7-4-错误的抛出及上抛"><span class="toc-text">7-4.错误的抛出及上抛</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#8-文件读写"><span class="toc-text">8.文件读写</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#8-1-一般读"><span class="toc-text">8-1.一般读</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-2-一般写"><span class="toc-text">8-2.一般写</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#8-3-大文件读取"><span class="toc-text">8-3.大文件读取</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#9-类"><span class="toc-text">9.类</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#9-1-构造函数"><span class="toc-text">9-1.构造函数</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-2-封装"><span class="toc-text">9-2.封装</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-3-继承"><span class="toc-text">9-3.继承</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-4-property装饰器"><span class="toc-text">9-4.@property装饰器</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-5-类的特殊属性与方法"><span class="toc-text">9-5.类的特殊属性与方法</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#9-5-1-dict"><span class="toc-text">9-5-1.__dict__</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-5-2-slots"><span class="toc-text">9-5-2.__slots__</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#9-5-3-运算符重载"><span class="toc-text">9-5-3.运算符重载</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#9-6-迭代行为"><span class="toc-text">9-6.迭代行为</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#10-常用模块"><span class="toc-text">10.常用模块</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#10-1-os-模块"><span class="toc-text">10-1.os 模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-2-sys-模块"><span class="toc-text">10-2.sys 模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-3-re模块"><span class="toc-text">10-3.re模块</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#10-4-其他模块"><span class="toc-text">10-4.其他模块</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#11-调试与测试"><span class="toc-text">11.调试与测试</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#11-1-assert"><span class="toc-text">11-1.assert</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#11-2-日志调试"><span class="toc-text">11-2.日志调试</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#12-练习"><span class="toc-text">12.练习</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#12-1-列表、字典解析"><span class="toc-text">12-1.列表、字典解析</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#12-2-collections使用"><span class="toc-text">12-2.collections使用</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#12-2-1-示例"><span class="toc-text">12-2-1.示例</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#12-2-2-扑克牌"><span class="toc-text">12-2-2.扑克牌</span></a></li></ol></li></ol></li></ol>
    
<style>
    .left-col .switch-btn,
    .left-col .switch-area {
        display: none;
    }
    .toc-level-4 i,
    .toc-level-4 ol {
        display: none !important;
    }
</style>
</div>
    
    <div class="article-entry" itemprop="articleBody">
      
        <h2 id="1-介绍"><a href="#1-介绍" class="headerlink" title="1.介绍"></a>1.介绍</h2><p>Python 是一门独特的语言，快速浏览一下他的要点：</p>
<ul>
<li><strong>面向对象</strong>：每一个变量都是一个类，有其自己的<strong>属性(attribute)</strong>与<strong>方法(method)</strong>。</li>
<li><strong>语法块</strong>：用缩进(四个空格)而不是分号、花括号等符号来标记。因此，行首的空格不能随意书写。</li>
<li><strong>注释</strong>：行内用“#”号，行间注释写在两组连续三单引号之间：<code>&#39;&#39;&#39;</code></li>
<li><strong>续行</strong>：行尾输入一个反斜杠加一个空格(<code>\</code>)，再换行。如果行尾语法明显未完成(比如以逗号结尾)，可以直接续行。</li>
<li><strong>打印与输入</strong>： 函数 print() 与 input()，注意 print() 的 sep 与 end 参数。 </li>
<li><strong>变量</strong>：无需指定变量类型，也不需要提前声明变量。<ul>
<li>删除变量：del()</li>
<li>复制变量：直接将变量a赋值给b，有时仅仅复制了一个“引用”。此后 b 与 a 的改动仍会互相影响。必要时使用 <code>a is b</code> 来判断是否同址。</li>
</ul>
</li>
<li><strong>模块</strong>：通过 <code>import pandas</code> 的方式加载模块(或者 <code>import pandas as pd</code>)，并用形如 <code>pandas.DataFrame</code>(或 <code>pd.DataFrame</code>)的方式调用模块内的方法。也可以使用 <code>from pandas import DataFrame</code> 的方式，这样在下文可以直接使用 <code>DataFrame</code> 作为调用名。</li>
<li><strong>帮助</strong>：配合使用 dir() 与 help() 命令；其中前者是输出变量所有的成员。以及查阅 <a href="https://docs.python.org/3/" target="_blank" rel="noopener">官网页面</a>。</li>
</ul>
<pre><code class="python">a = [1, 2]
b = a
print(id(a) - id(b))  # 地址差为 0，表示实质是同址的</code></pre>
<blockquote>
<p>结果：0</p>
</blockquote>
<pre><code class="python">b.append(3)
print(a)  # 只改动了 b，但 a 也跟着变动了</code></pre>
<blockquote>
<p>结果：[1, 2, 3]</p>
</blockquote>
<pre><code class="python">a is b</code></pre>
<blockquote>
<p>结果： True</p>
</blockquote>
<p>使用切片来重新分配空间：</p>
<pre><code class="python">a is a[:]</code></pre>
<blockquote>
<p>结果：False</p>
</blockquote>
<h2 id="2-数据结构"><a href="#2-数据结构" class="headerlink" title="2.数据结构"></a>2.数据结构</h2><p>Python 原生的数据结构包括：</p>
<h3 id="2-1-数字-num"><a href="#2-1-数字-num" class="headerlink" title="2-1.数字(num)"></a>2-1.数字(num)</h3><p>细分为整数(int)与浮点数(float)两种。</p>
<ul>
<li>四则运算：<code>+</code>， <code>-</code>， <code>*</code>， <code>/</code> ，乘方： <code>**</code></li>
<li>整除： <code>5 // 2 = 2</code>，取余：<code>5 % 2 = 1</code></li>
<li>自运算： <code>a += 1</code> (四则与乘方均可类似自运算)</li>
</ul>
<p>以及一些细节：</p>
<ul>
<li>运算两数中只要有一个浮点数，结果就是浮点数；</li>
<li>整数相除，即使能除尽，结果也是浮点数；</li>
<li>Python 内部的机制解决了整数溢出的问题，不用担心。</li>
</ul>
<h3 id="2-2-布尔-bool-与逻辑"><a href="#2-2-布尔-bool-与逻辑" class="headerlink" title="2-2.布尔(bool)与逻辑"></a>2-2.布尔(bool)与逻辑</h3><p>首字母大写 True / False. </p>
<ul>
<li>逻辑运算符：与 <code>A and B</code>，或 <code>A or B</code>，非 <code>not A</code></li>
<li>逻辑关系符：等于 <code>==</code>， 不等于 <code>!=</code>. 其他不赘述。</li>
<li>几种逻辑判断例子：</li>
</ul>
<table>
<thead>
<tr>
<th>变量 x</th>
<th>x = []</th>
<th>x = 0</th>
<th>x = 2</th>
</tr>
</thead>
<tbody><tr>
<td>bool(x)</td>
<td>False</td>
<td>False</td>
<td>True</td>
</tr>
<tr>
<td>if x: …</td>
<td>False</td>
<td>False</td>
<td>True</td>
</tr>
<tr>
<td>if x is None: …</td>
<td>False</td>
<td>False</td>
<td>False</td>
</tr>
</tbody></table>
<h3 id="2-3-序列-sequence"><a href="#2-3-序列-sequence" class="headerlink" title="2-3.序列(sequence)"></a>2-3.序列(sequence)</h3><p>序列主要包括<strong>字符串(str)、列表(list)与元祖(tuple)</strong>三类。</p>
<ul>
<li>序列索引规则：<ul>
<li>索引从0开始，到 N-1 结束。</li>
<li>切片：切片的索引是<strong>左闭右开</strong>的。<ul>
<li>seq[0:2](从 0 到 1)</li>
<li>seq[2:](从 2 到尾)</li>
<li>seq[:3] (从头到 2)</li>
<li>seq<a href="全部">:</a></li>
<li>seq<a href="从头到9，每两个取一个">:10:2</a></li>
<li>seq<a href="全部，每两个取一个">::2</a></li>
</ul>
</li>
<li>索引允许负数：seq(-1) 与 seq(N - 1) 等同，seq(-3:-1)与 seq(N-3:N-1) 等同。</li>
</ul>
</li>
<li>序列通用函数：<ul>
<li><code>len()</code>：返回序列长度。</li>
<li><code>+/*</code> ：加号用于连接两个序列，乘号重复排列若干次再连接。</li>
<li><code>seq1 in seq2</code>：如果 seq1 这个片段可以在 seq2 中被找到，返回 True.</li>
<li><code>index</code>：在 <code>seq1 in seq2</code> 为 True 时使用，<code>seq2.index(seq1)</code> 表示 seq1 首次出现于 seq2 中的位置。</li>
<li><code>max()/min()</code>：返回序列中的最值。如果不是数字，则按 ASCII 码顺序返回。</li>
<li><code>cmp(seq1, seq2)</code>：比较大小。结果为负，则表示 seq1 较小。</li>
</ul>
</li>
</ul>
<h4 id="2-3-1-字符串-str"><a href="#2-3-1-字符串-str" class="headerlink" title="2-3-1.字符串(str)"></a>2-3-1.字符串(str)</h4><p>写于一对双引号或单引号内。用<code>str()</code>可以强制转换为字符串。</p>
<ul>
<li>转义：反斜杠。如果强制不解释字符串，在左引号前加字母 r 即可： <code>r&quot;c:\new&quot;</code>.</li>
<li>分割与连接：<code>**.split()</code> 与 <code>**.join()</code>.</li>
</ul>
<pre><code class="python">s = &quot; I love Python&quot;  # 首位是空格
lst = s.split(&#39; &#39;)
lst1 = &#39;-&#39;.join(lst)

print(lst, &#39;\n&#39;, lst1)</code></pre>
<blockquote>
<p>结果：<br>[‘’, ‘I’, ‘love’, ‘Python’]<br>-I-love-Python</p>
</blockquote>
<ul>
<li>紧切：<code>strip()</code> 去掉字符串首尾两端的空格。方法 lstrip()/rstrip() 则只切除首端/尾端的空格。</li>
</ul>
<pre><code class="python">s.strip()</code></pre>
<blockquote>
<p>结果：’I love Python’</p>
</blockquote>
<ul>
<li>大小写转换：如下几个方法：<ul>
<li>首字母大写：s.title()</li>
<li>全大写：s.upper()</li>
<li>全小写：s.lower()</li>
<li>句首大写：s.capitalize()</li>
</ul>
</li>
<li>格式化：字符串格式化是一种实用功能。通过 <code>.format()</code> 成员函数完成。</li>
</ul>
<pre><code class="python">&#39;I like {} and {}&#39;.format(&#39;Python&#39;, &#39;you&#39;)</code></pre>
<blockquote>
<p>结果： ‘I like Python and you’</p>
</blockquote>
<pre><code class="python">&#39;{0} + {2} = {1}&#39;.format (10, 20, &#39;Python &#39;)  # 按顺序引用</code></pre>
<blockquote>
<p>结果：’10 + Python  = 20’</p>
</blockquote>
<pre><code class="python">&#39;{0} * {1} = {0}&#39;.format (10, &#39;Python &#39;)  # 编号反复引用</code></pre>
<blockquote>
<p>结果： ‘10 * Python  = 10’</p>
</blockquote>
<p><strong>格式化控制码：</strong></p>
<table>
<thead>
<tr>
<th>控制码</th>
<th>含义</th>
<th>控制码</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>:s</td>
<td>字符串</td>
<td>:c</td>
<td>单个字符</td>
</tr>
<tr>
<td>:b/o/x/d</td>
<td>二、八、十六、十进制数</td>
<td>:e/f</td>
<td>科学计数法/浮点数</td>
</tr>
</tbody></table>
<p>一些复杂控制的例子：</p>
<table>
<thead>
<tr>
<th>例子</th>
<th>含义</th>
<th>例子</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>:.2f/:+.2f</td>
<td>两位小数/带符号两位小数</td>
<td>: .2f</td>
<td>正数前补空格的两位小数</td>
</tr>
<tr>
<td>:,</td>
<td>逗号分隔符</td>
<td>:.2%</td>
<td>百分比两位小数</td>
</tr>
<tr>
<td>:.2e</td>
<td>科学计数法两位小数</td>
<td>:^4d</td>
<td>总宽四位居中对齐</td>
</tr>
<tr>
<td>:&gt;4d/&lt;4d</td>
<td>总宽四位左/右对齐</td>
<td>:0&gt;4d</td>
<td>总宽四位左侧补零</td>
</tr>
</tbody></table>
<p>举例：</p>
<pre><code class="python">&quot;{:0&gt;7.2f} is an odd number&quot;.format(123.4)  # 总宽 7 位小数点后 2 位，左侧补零</code></pre>
<blockquote>
<p>结果：’0123.40 is an odd number’</p>
</blockquote>
<p><strong>其他实用的字符串函数：</strong></p>
<ul>
<li>str.replace(old, new[, times])：将字符串中前 times 个 old 子串替换为 new。Times 不指定时默认替换全部。</li>
<li>str.isdigit()：判断字符串是否每一位都是数字，返回 True 或者 False。</li>
</ul>
<p>字符串中正则表达式的内容参见本文附录。</p>
<h4 id="2-3-2-列表-list"><a href="#2-3-2-列表-list" class="headerlink" title="2-3-2.列表(list)"></a>2-3-2.列表(list)</h4><p>中括号式的结构, <code>list()</code>用于强制转换类型。</p>
<pre><code class="python">lst = [1, 2, 3]
print(lst)</code></pre>
<blockquote>
<p>结果： [1, 2, 3]</p>
</blockquote>
<pre><code class="python"># 【反转】：其中第二种方式会更改现有的列表
lst1 = list(reversed(lst))
lst.reverse()
print(lst1, lst)</code></pre>
<blockquote>
<p>结果： [3, 2, 1] [3, 2, 1]</p>
</blockquote>
<pre><code class="python"># 【追加】：元素 append()，另一个列表：extend()
lst.append(4)
print(lst)</code></pre>
<blockquote>
<p>结果： [3, 2, 1, 4]</p>
</blockquote>
<pre><code class="python">lst.extend(lst1)
print(lst)</code></pre>
<blockquote>
<p>结果： [3, 2, 1, 4, 3, 2, 1]</p>
</blockquote>
<pre><code class="python"># 【插入】：lst.insert(idx, obj) 会在 lst[idx] 处插入 obj，然后依次后移原有项
lst.insert(1, 100)
print(lst)</code></pre>
<blockquote>
<p>结果：[3, 100, 2, 1, 4, 3, 2, 1]</p>
</blockquote>
<pre><code class="python"># 【删除】：lst.remove(obj) 会删除首个匹配值，若无匹配会报错；
#  lst.pop(idx) 会返回 lst[idx]，并将其删除。如果不指定 idx，默认为列表尾
lst.remove(2)
print(lst)</code></pre>
<blockquote>
<p>结果：[3, 100, 1, 4, 3, 2, 1]</p>
</blockquote>
<pre><code class="python">tmp = lst.pop()
print(lst, &quot;\n&quot;, tmp)</code></pre>
<blockquote>
<p>结果：<br>[3, 100, 1, 4, 3, 2]<br>1</p>
</blockquote>
<pre><code class="python"># 【搜索】：使用序列通用函数即可。用 count(obj) 可以计算频数。
# 【排序】：sort() 方法。如果指定 reverse 参数，可降序排序。
lst.sort(reverse=True)
print(lst)</code></pre>
<blockquote>
<p>结果： [100, 4, 3, 3, 2, 1]</p>
</blockquote>
<pre><code class="python"># 【清空】：clear()
lst.clear()
print(lst)</code></pre>
<blockquote>
<p>结果：[]</p>
</blockquote>
<h4 id="2-3-3-元组-tuple"><a href="#2-3-3-元组-tuple" class="headerlink" title="2-3-3.元组(tuple)"></a>2-3-3.元组(tuple)</h4><p>圆括号式的结构，是一种<strong>不可变</strong>序列。</p>
<pre><code class="python">a = (1, &#39;string &#39;, [1 ,2])
print(a)</code></pre>
<blockquote>
<p>结果：(1, ‘string ‘, [1, 2])</p>
</blockquote>
<h3 id="2-4-字典-dict"><a href="#2-4-字典-dict" class="headerlink" title="2-4.字典(dict)"></a>2-4.字典(dict)</h3><p>字典是一种类哈希表的数据结构，内部无序，通过键值对(key: value)的形式存储数据。几种字典初始化的方式：</p>
<pre><code class="python"># 小字典直接赋值
d1 = {&quot;name&quot;: &quot;wklchris&quot;, &quot;gender&quot;: &quot;male&quot;}
# 利用字典增加键值对的方法
d2 = {}
d2[&#39;name&#39;] = &#39;wklchris&#39;
# 一个值赋给多个键
d3 = {}.fromkeys((&quot;name&quot;, &quot;gender&quot;), &quot;NA&quot;)
# 强制格式转换
d4 = dict(name=&quot;wklchris&quot;, gender=&quot;male&quot;)

print(d1, d2, d3, d4, sep=&quot;\n&quot;)</code></pre>
<blockquote>
<p>结果：<br>{‘name’: ‘wklchris’, ‘gender’: ‘male’}<br>{‘name’: ‘wklchris’}<br>{‘name’: ‘NA’, ‘gender’: ‘NA’}<br>{‘name’: ‘wklchris’, ‘gender’: ‘male’}</p>
</blockquote>
<p><strong>字典的操作方法</strong>：</p>
<pre><code class="python">len(d1)</code></pre>
<blockquote>
<p>结果：2</p>
</blockquote>
<pre><code class="python"># 【复制】：
dd = d1.copy()
dd is d1</code></pre>
<blockquote>
<p>结果： False</p>
</blockquote>
<pre><code class="python"># 【查找键名称】：
&quot;name&quot; in dd</code></pre>
<blockquote>
<p>结果： True</p>
</blockquote>
<pre><code class="python"># 【删除键值对】
del(dd[&quot;name&quot;])</code></pre>
<pre><code class="python"># 【get】
dd.get(&quot;age&quot;, &quot;Nothing&quot;)  # 如果键不存在，返回“Nothing”</code></pre>
<blockquote>
<p>结果：’Nothing’</p>
</blockquote>
<pre><code class="python"># 【setdefault】
dd.setdefault(&quot;name&quot;, &quot;wklchris&quot;)  # 如果键不存在，就新建该键，并赋值</code></pre>
<blockquote>
<p>结果：’wklchris’</p>
</blockquote>
<pre><code class="python">print(dd)</code></pre>
<blockquote>
<p>结果： {‘name’: ‘wklchris’, ‘gender’: ‘male’}</p>
</blockquote>
<pre><code class="python"># 【输出键值】：
list(dd.items())</code></pre>
<blockquote>
<p>结果：[(‘name’, ‘wklchris’), (‘gender’, ‘male’)]</p>
</blockquote>
<pre><code class="python">list(dd.keys())</code></pre>
<blockquote>
<p>结果：[‘name’, ‘gender’]</p>
</blockquote>
<pre><code class="python">list(dd.values())</code></pre>
<blockquote>
<p>结果： [‘wklchris’, ‘male’]</p>
</blockquote>
<pre><code class="python"># 【弹出键值对】：pop(key) / popitem(key)
# 其中，后者会随机弹出一个键值对
tmp = dd.pop(&quot;gender&quot;)
print(dd, tmp)</code></pre>
<blockquote>
<p>结果：{‘name’: ‘wklchris’} male</p>
</blockquote>
<pre><code class="python"># 【更新】：update(ref_dict) 以 ref_dict 为准，更新当前字典
d4 = {&quot;name&quot;: &quot;Test&quot;, &quot;Age&quot;: 3}
dd.update(d4)
print(dd)</code></pre>
<blockquote>
<p>结果： {‘name’: ‘Test’, ‘Age’: 3}</p>
</blockquote>
<h3 id="2-5-集合-set"><a href="#2-5-集合-set" class="headerlink" title="2-5.集合(set)"></a>2-5.集合(set)</h3><p><em>本文只讨论可变集合，关于不可变集合的内容，参考 <code>help(frozenset)</code>。</em></p>
<p>集合是一种无序的数据存储方式，且内部元素具有唯一性。集合与字典一样都可以用花括号的形式创立。但在书写 <code>a={}</code> 时，Python 会将其识别为字典类型。</p>
<ul>
<li>增添：add() / update()</li>
<li>删除：remove() / discard()，区别在于后者搜索无结果会报错。</li>
<li>从属：a.issubset(b) 集合 a 是否是 b 的子集；a.issuperset(b) 集合 a 是否是 b 的父集。a == b 两集合是否全等。</li>
<li>集合运算：集合运算不会改变参与运算的集合本身。<ul>
<li>并集： <code>a | b</code> 或者 <code>a.union(b)</code></li>
<li>交集： <code>a &amp; b</code> 或者 <code>a.intersection(b)</code></li>
<li>补集： <code>a - b</code> 或者 <code>a.difference(b)</code></li>
</ul>
</li>
</ul>
<p>注意：在字符串强制转换为集合时，<strong>必要时使用中括号先转为列表</strong>(否则字符串会被拆分为单个字符后再进行转换)。例如：</p>
<pre><code class="python">ss = {&quot;a&quot;, &quot;b&quot;, &quot;c&quot;}
ss | set(&quot;de&quot;)</code></pre>
<blockquote>
<p>结果：{‘a’, ‘b’, ‘c’, ‘d’, ‘e’}</p>
</blockquote>
<pre><code class="python">ss | set([&quot;de&quot;])</code></pre>
<blockquote>
<p>结果： {‘a’, ‘b’, ‘c’, ‘de’}</p>
</blockquote>
<h2 id="3-基本语句"><a href="#3-基本语句" class="headerlink" title="3.基本语句"></a>3.基本语句</h2><p>同大多数程序语言一样，Python 拥有 if, for, while 语句。什么？switch 语句？使用字典就好。</p>
<h3 id="3-1-if语句与三元操作"><a href="#3-1-if语句与三元操作" class="headerlink" title="3-1.if语句与三元操作"></a>3-1.if语句与三元操作</h3><p>在 Python 中，<code>else if</code>被缩写为单个关键词<code>elif</code>.</p>
<pre><code class="python">if 1.0 &gt; 1:
    a = 1
elif 1.0 &lt; 1:
    a = 2
else:
    a = 3

a</code></pre>
<blockquote>
<p>结果：3</p>
</blockquote>
<p>值得一提的是，Python 中的 if 语句支持链式比较，形如 <code>a &lt; x &lt; b</code>, <code>a &lt; x &gt;= b</code> 等：</p>
<pre><code class="python">a = 0
if 1 &lt; 2 &gt; 1.5:
    a = 1
a</code></pre>
<blockquote>
<p>结果： 1</p>
</blockquote>
<p>三元操作实质是高度简化的 if 环境，形如 X = a if flag else b：</p>
<pre><code class="python">a = 1 if 2 &lt; 1 else 2
a</code></pre>
<blockquote>
<p>结果： 2</p>
</blockquote>
<h3 id="3-2-for-语句"><a href="#3-2-for-语句" class="headerlink" title="3-2.for 语句"></a>3-2.for 语句</h3><p>Python 的循环语句中，像其他语言一样，有 <code>break</code>(跳出循环体) 与 <code>continue</code>(循环步进) 关键词可以使用。</p>
<p>for 语句借助关键词 in 使用：(函数 range(N, M=0, s=1) 是一个生成等差数列的函数，位于左闭右开区间 $[M, N)$ 上且公差为 s)。</p>
<pre><code class="python">for i in range(3):
    print(i)</code></pre>
<blockquote>
<p>结果：<br>    0<br>    1<br>    2</p>
</blockquote>
<p>注意到字典的 d.items(), d.keys(), d.values() 命令也常常用于 for 语句：</p>
<pre><code class="python">d = {&quot;a&quot;: 1, &quot;b&quot;: 2, &quot;c&quot;: 3}
for k, v in d.items():
    print(k, v)</code></pre>
<blockquote>
<p>结果<br> b 2<br> c 3<br> a 1</p>
</blockquote>
<p>以上等价于：</p>
<pre><code class="python">for k in d.keys():
    print(k, d[k])</code></pre>
<blockquote>
<p>结果<br> b 2<br> c 3<br> a 1</p>
</blockquote>
<p>Python中的for语句可选<code>else</code>语法块，表示for语句<strong>正常结束</strong>后执行的内容(中途<code>break</code>不属于正常结束)。这对于处理一些<code>break</code>操作很有帮助。</p>
<pre><code class="python">a = 0
flag = 0
for i in range(5):
    if i &gt; 2:
        flag = 1
        break
if flag == 1:
    a = 1
a</code></pre>
<blockquote>
<p>结果 1</p>
</blockquote>
<p>这在 Python 中显得太复杂了，直接使用<code>for...else...</code>即可：</p>
<pre><code class="python">a = 1
for i in range(5):
    if i &gt; 1:
        break
else:
    a = 0
a</code></pre>
<blockquote>
<p>结果 1</p>
</blockquote>
<h3 id="3-3-while-语句"><a href="#3-3-while-语句" class="headerlink" title="3-3.while 语句"></a>3-3.while 语句</h3><p>while语句的else语法块，指明了退出while 循环后立刻执行的内容；它不是必需的。</p>
<p>如果你想要将while语句内部的参数传出(比如下例的计数器终值)，这是一个不错的方案。</p>
<pre><code class="python">count = 1
while count &lt; 5:
    a = count
    count *= 2
else:
    b = count

print(a, b)</code></pre>
<blockquote>
<p>结果 4 8</p>
</blockquote>
<h3 id="3-4-列表解析"><a href="#3-4-列表解析" class="headerlink" title="3-4.列表解析"></a>3-4.列表解析</h3><p>列表解析是一种创建列表的高度缩写方式：</p>
<pre><code class="python">lst = [x ** 2 for x in range(4)]
lst</code></pre>
<blockquote>
<p>结果 [0, 1, 4, 9]</p>
</blockquote>
<p>也可以配合 if 语句：</p>
<pre><code class="python">lst = [x ** 2 for x in range(4) if x &gt; 0]
lst</code></pre>
<blockquote>
<p>结果 [1, 4, 9]</p>
</blockquote>
<p>类似的，也有字典解析，以及下文会介绍的生成器，也有生成器解析(把外围的括号换成花括号即可)：</p>
<pre><code class="python">{n: n ** 2 for n in range(3)}</code></pre>
<blockquote>
<p>结果 {0: 0, 1: 1, 2: 4}</p>
</blockquote>
<h2 id="4-函数"><a href="#4-函数" class="headerlink" title="4.函数"></a>4.函数</h2><p>本节介绍 Python 函数的基础特点，以及一些实用函数。</p>
<h3 id="4-1-函数定义与判断"><a href="#4-1-函数定义与判断" class="headerlink" title="4-1.函数定义与判断"></a>4-1.函数定义与判断</h3><p>使用 <code>def</code> 关键字。三连双引号间的内容被视为函数的帮助字符串，可以通过 <code>help()</code> 命令查看。</p>
<pre><code class="python">def func(a, b=0):
    &quot;&quot;&quot;
    This is a function that can meow.
    &quot;&quot;&quot;
    return &quot; &quot;.join([&quot;meow&quot;] * (a + b))</code></pre>
<p>调用函数：</p>
<pre><code class="python">func(2)  # 单参数，仅 a </code></pre>
<blockquote>
<p>结果 ‘meow meow’</p>
</blockquote>
<pre><code class="python">func(2, 3)  # 双参数， a 与 b 都被传入</code></pre>
<blockquote>
<p>结果  ‘meow meow meow meow meow’</p>
</blockquote>
<pre><code class="python">help(func)</code></pre>
<blockquote>
<p> Help on function func in module <strong>main</strong>:<br> func(a, b=0)<br>        This is a function that can meow.</p>
</blockquote>
<p>通过 <code>callable()</code> 可以判断一个对象是否是一个可调用的函数：</p>
<pre><code class="python">callable(func)</code></pre>
<blockquote>
<p>结果 True</p>
</blockquote>
<h3 id="4-2-不定参函数"><a href="#4-2-不定参函数" class="headerlink" title="4-2.不定参函数"></a>4-2.不定参函数</h3><p>利用序列(或元组)与字典，向函数传参。前者在传入时需要加上一个星号，后者需要两个。</p>
<pre><code class="python">lst = [1, 3, 4]
d = {&quot;a&quot;: 2, &quot;b&quot;: 3, &quot;c&quot;: 5}
print(&quot;{}+{}={}&quot;.format(*lst), &quot;{a}+{b}={c}&quot;.format(**d))</code></pre>
<blockquote>
<p>结果: 1+3=4 2+3=5</p>
</blockquote>
<h3 id="4-3-zip-函数"><a href="#4-3-zip-函数" class="headerlink" title="4-3.zip 函数"></a>4-3.zip 函数</h3><p>zip() 函数的作用是“合并”多个列表为一个。其返回值是一个列表，列表内的元素类型是元组。如果待合并的列表长度不同，以最短的为准。</p>
<pre><code class="python">a = [1, 2, 3, 4]
b = [5 ,6, 7]
c = &quot;abcd&quot;
list(zip(a, b, c))</code></pre>
<blockquote>
<p>结果: [(1, 5, ‘a’), (2, 6, ‘b’), (3, 7, ‘c’)]</p>
</blockquote>
<p>它比较常用于交换字典的键与值：</p>
<pre><code class="python">dict(zip(d.values(), d.keys()))</code></pre>
<blockquote>
<p>结果: {2: ‘a’, 3: ‘b’, 5: ‘c’}</p>
</blockquote>
<h3 id="4-4-lambda-函数"><a href="#4-4-lambda-函数" class="headerlink" title="4-4.lambda 函数"></a>4-4.lambda 函数</h3><p>一种匿名函数的声明方式。如果你使用过 MATLAB，你可能熟悉这一类概念。</p>
<pre><code class="python">func = lambda x, y: x + y
func(2, 5)</code></pre>
<blockquote>
<p>结果: 7</p>
</blockquote>
<h3 id="4-5-map-函数"><a href="#4-5-map-函数" class="headerlink" title="4-5.map 函数"></a>4-5.map 函数</h3><p>map() 能够对传入的序列进行依次操作，并将结果返回为一个可转换为列表的 map 对象。通常列表解析(或生成器解析)可以实现与其同样的工作。</p>
<pre><code class="python">lst = list(map(lambda x: x + 1, range (5)))
print(lst)</code></pre>
<blockquote>
<p>结果: [1, 2, 3, 4, 5]</p>
</blockquote>
<pre><code class="python">f = lambda x: x + 1
[f(x) for x in range(5)]</code></pre>
<blockquote>
<p>结果:  [1, 2, 3, 4, 5]</p>
</blockquote>
<h3 id="4-6-filter-函数"><a href="#4-6-filter-函数" class="headerlink" title="4-6.filter 函数"></a>4-6.filter 函数</h3><p>给定序列，对于满足某规则的部分(即 True)，予以返回。</p>
<pre><code class="python">list(filter(lambda x: x &gt; 0, range(-3, 3)))</code></pre>
<blockquote>
<p>结果: [1, 2]</p>
</blockquote>
<h3 id="4-8-reduce-函数"><a href="#4-8-reduce-函数" class="headerlink" title="4-8.reduce 函数"></a>4-8.reduce 函数</h3><p>该函数在 Python 2 中是可以直接调用的，但在 Python 3 中需要从 functools 模块进行调用。</p>
<pre><code class="python">from functools import reduce
reduce(lambda x, y: x + y, range (5))  # 0+1+2+3+4</code></pre>
<blockquote>
<p>结果: 10</p>
</blockquote>
<h3 id="4-9-enumerate-函数"><a href="#4-9-enumerate-函数" class="headerlink" title="4-9.enumerate 函数"></a>4-9.enumerate 函数</h3><p>它允许你像 d.items() 那样，用类似的方式操作列表：</p>
<pre><code class="python">a = [1, 3, 5]
for i, v in enumerate(a):
    print(&quot;lst[{}] = {}&quot;.format(i, v))</code></pre>
<blockquote>
<p>结果<br>    lst[0] = 1<br>    lst[1] = 3<br>    lst[2] = 5</p>
</blockquote>
<h2 id="5-装饰器：算子"><a href="#5-装饰器：算子" class="headerlink" title="5.装饰器：算子"></a>5.装饰器：算子</h2><p>装饰器是<strong>函数的函数</strong>——传入的参数是一个函数，返回的值也是一个函数。相当于一个函数集到另一个函数集的映射，可以理解为数学意义上的算子。</p>
<p>首先来看一个简单的例子：函数可以被赋值给一个变量。</p>
<pre><code class="python">def pyrint(data=&quot;Python&quot;):
    return data.upper()

f = pyrint
f()</code></pre>
<blockquote>
<p>结果: ‘PYTHON’</p>
</blockquote>
<p>还可以通过 <code>__name__</code> 来得到当前函数的名称：</p>
<pre><code class="python">f.__name__</code></pre>
<blockquote>
<p>结果: ‘pyrint’</p>
</blockquote>
<p>那什么时候需要装饰器呢？比如在函数需要被重用、但又不能直接改写 <code>def</code> 的场合(在维护中应该不少见吧！)。例如，我们希望在返回值之前，把函数名也打印出来：</p>
<pre><code class="python">def showname(func):
    def subfunc(*args, **kwarg):
        print(&quot;FUNCTION {} called.&quot;.format(func.__name__))
        return func(*args, **kwarg)
    return subfunc</code></pre>
<p>这样如果我们通过 <code>showname(pyrint)</code> 这种形式，就能够在 <code>pyrint</code> 函数被调用之前，额外打印一行内容。</p>
<p>想要改动该函数，不需要改动 <code>def</code> 语句以下的内容，只需要用 <code>@showname</code> 命令来应用这个装饰器：</p>
<pre><code class="python">@showname
def pyrint(data=&quot;Python&quot;):
    return data.upper()</code></pre>
<pre><code class="python">pyrint()</code></pre>
<blockquote>
<p>结果:<br>FUNCTION pyrint called.<br>‘PYTHON’</p>
</blockquote>
<p>如果装饰器需要传递参数，那么，需要在定义时，外层再嵌套一个函数：</p>
<pre><code class="python">def showname(num=1):
    def decorator(func):
        def subfunc(*args, **kwarg):
            print(&quot;Call time: {}. FUNCTION {} called.&quot;.format(num, func.__name__))
            return func(*args, **kwarg)
        return subfunc
    return decorator

@showname(2)
def pyrint(data=&quot;Python&quot;):
    return data.upper()

pyrint()</code></pre>
<blockquote>
<p>结果<br>Call time: 2. FUNCTION pyrint called.<br>‘PYTHON’</p>
</blockquote>
<p>不过装饰器被应用于函数定义之前时，函数的 <code>__name__</code> 属性会改变。比如上例：</p>
<pre><code class="python">pyrint.__name__</code></pre>
<blockquote>
<p>结果: ‘subfunc’</p>
</blockquote>
<p>使用模块 <code>functools</code> 来解决这一问题：</p>
<pre><code class="python">import functools

def showname(num=1):
    def decorator(func):
        @functools.wraps(func)  # 加上这一行
        def subfunc(*args, **kwarg):
            print(&quot;Call time: {}. FUNCTION {} called.&quot;.format(num, func.__name__))
            return func(*args, **kwarg)
        return subfunc
    return decorator

@showname(2)
def pyrint(data=&quot;Python&quot;):
    return data.upper()

pyrint.__name__</code></pre>
<blockquote>
<p>结果: ‘pyrint’</p>
</blockquote>
<h2 id="6-迭代器-itertools"><a href="#6-迭代器-itertools" class="headerlink" title="6.迭代器 [itertools]"></a>6.迭代器 [itertools]</h2><p><strong>迭代器</strong>与<strong>生成器</strong>在内存优化上很有意义。</p>
<h3 id="6-1-迭代器"><a href="#6-1-迭代器" class="headerlink" title="6-1.迭代器"></a>6-1.迭代器</h3><p>迭代器最显著的特征是拥有 <code>__iter__()</code> 和 <code>__next__()</code> 方法；它像一个链表。如果它指向末尾，那么再次执行 <code>__next__()</code> 时会报错。一个例子：</p>
<pre><code class="python">a = [1, 2, 3]
b = iter(a)
print(b.__next__(), b.__next__())  # 或者使用 next(b)</code></pre>
<blockquote>
<p>结果: 1 2</p>
</blockquote>
<p>实际上，Python3内置了一个<code>itertools</code>的库，里面有诸如<code>cycle</code>和<code>count</code>等适用于迭代器的函数：</p>
<pre><code class="python">import itertools

# count: 给定首项与公差的无穷等差数列
p = itertools.count(start = 1, step = 0.5)
print(p.__next__(), p.__next__())

# cycle: 周期循环的无穷序列
p = itertools.cycle(list(&quot;AB&quot;))
print(next(p), next(p), next(p))

# islice: 从无穷序列中切片
p = itertools.cycle(list(&quot;AB&quot;))
print(list(itertools.islice(p, 0, 4)))</code></pre>
<blockquote>
<p>结果 :<br> 1 1.5<br> A B A<br> [‘A’, ‘B’, ‘A’, ‘B’]</p>
</blockquote>
<p>请时刻注意<strong>当前指向的迭代器位置</strong>——失之毫厘，谬以千里。</p>
<h3 id="6-2-生成器"><a href="#6-2-生成器" class="headerlink" title="6-2.生成器"></a>6-2.生成器</h3><p>生成器是迭代器的一种，其实质是<strong>定义中含有<code>yield</code>关键词的函数</strong>。它没有return()语句。</p>
<p>生成器可以直接使用类似列表解析的方式，称为生成器解析。例如：<code>(i for i in range(10)</code>。</p>
<pre><code class="python">def Fib(N):  # 斐波那契数列
    n, former, later = 0, 0, 1
    while n &lt; N:
        yield later
        former, later = later, later + former
        n += 1

list(Fib(5))</code></pre>
<blockquote>
<p>结果 : [1, 1, 2, 3, 5]</p>
</blockquote>
<p>上例与普通的写法看上去差别不大，但实际上可以将while语句改写为 while True，删除变量 n，在外部借助<code>itertools</code>的<code>islice</code>函数来截取。<br>这在函数定义时对代码的压缩是显然的。</p>
<pre><code class="python">def iterFib():
    former, later = 0, 1
    while True:
        yield later
        former, later = later, later + former

list(itertools.islice(iterFib(), 0, 5))</code></pre>
<blockquote>
<p>结果 : [1, 1, 2, 3, 5]</p>
</blockquote>
<h2 id="7-错误：try-语句"><a href="#7-错误：try-语句" class="headerlink" title="7.错误：try() 语句"></a>7.错误：try() 语句</h2><p>常见的错误有以下几种：</p>
<ul>
<li>ZeroDivisionError: 除数为 0.</li>
<li>SyntaxError：语法错误。</li>
<li>IndexError：索引超界。</li>
<li>KeyError：字典键不存在。</li>
<li>IOError：读写错误。</li>
</ul>
<p>try() 语句的常见写法：</p>
<pre><code class="python">try:
    a = 1 
except ZeroDivisionError as e:
    print(e)
    exit()
else:  # 如果无错误，执行
    print(a)
finally:  # 不管有无错误均执行
    print(&quot;-- End --&quot;)</code></pre>
<blockquote>
<p>结果 :<br>  1<br>– End –</p>
</blockquote>
<p>其中，else 与 finally 语句都不是必需的。如果不想输出错误信息、或不能预先判断可能的错误类型，可以使用仅含 exit() 语句的 except 块。</p>
<h3 id="7-1-多个-except-块"><a href="#7-1-多个-except-块" class="headerlink" title="7-1.多个 except 块"></a>7-1.多个 except 块</h3><p>一个 try 语法块是可以跟着多个<code>except</code> 的；如果靠前的 <code>except</code> 捕获了错误，之后的就不会运行。<br>这也就是说，如果错误之间有继承关系时，子错误需要放在父错误之前尝试 <code>except</code>，否则子错误永远也不可能被捕获。</p>
<p>比如上一节的例子中，ZeroDivisionError是ArithmeticError下的子错误，而ArithmeticError又是Exception下的子错误<br>(当不清楚错误的类型时，Exception 可以捕获绝大多数错误)。关于错误的继承关系，参考：<a href="https://docs.python.org/3/library/exceptions.html#exception-hierarchy" target="_blank" rel="noopener">Python - Exception Hierarchy 官方页面</a>。</p>
<p><strong>一个例子：</strong></p>
<pre><code class="python">try:
    a = 1 / 0
except Exception:
    print(&quot;Exception&quot;)
    exit()
except ZeroDivisionError:
    print(&quot;ZeroDivisionError&quot;)
    exit()
else:
    print(&quot;No error.&quot;)
finally:
    print(&quot;-- End --&quot;)</code></pre>
<blockquote>
<p>结果： Exception 与 – End –。</p>
</blockquote>
<h3 id="7-3-错误的捕获"><a href="#7-3-错误的捕获" class="headerlink" title="7-3.错误的捕获"></a>7-3.错误的捕获</h3><p>错误在很多地方都可能发生，那是否需要在可能的地方都加上 <code>try</code> 语句呢？</p>
<blockquote>
<p>当然不是。建议只在主代码中加入 try 语句，因为 Python 会自动跟踪到错误产生的源头何在。</p>
</blockquote>
<h3 id="7-4-错误的抛出及上抛"><a href="#7-4-错误的抛出及上抛" class="headerlink" title="7-4.错误的抛出及上抛"></a>7-4.错误的抛出及上抛</h3><p>有时候需人为抛出一个错误，这是使用<code>raise</code>即可：</p>
<pre><code class="python"># raise TypeError(&quot;Wrong type.&quot;)</code></pre>
<p>如果在函数中没有处理错误的语句，可能在捕获错误后将其上抛。记住，捕获错误只是为了记录错误的产生，并不意味者必须原地解决错误。</p>
<pre><code class="python">def makeerror(n):
    if n == 0:
        raise ValueError(&quot;Divided by zero.&quot;)
    return 1 / n

def callerror():
    try:
        makeerror(0)
    except ValueError as e:
        print(&quot;ValueError detected.&quot;)
        raise

# 输出 &quot;ValueError detected.&quot; 并打印错误日志
# callerror()</code></pre>
<p>上面的 raise 命令没有紧跟任何参数，表示将错误原样上抛。你也可以手动指定上抛的错误类型，并不需要与原错误类型一致。甚至你可以定义一个错误(继承某一错误类)：</p>
<pre><code class="python">class MyError(ValueError):
    print(&quot;This is MyError.&quot;)

# raise MyError</code></pre>
<blockquote>
<p>结果： This is MyError.</p>
</blockquote>
<h2 id="8-文件读写"><a href="#8-文件读写" class="headerlink" title="8.文件读写"></a>8.文件读写</h2><p>open() 函数用于文件的读写操作。一般我们会在操作文件时，引入<code>os</code>模块。</p>
<pre><code class="python">import os</code></pre>
<p><code>open()</code> 函数常常配合<code>with</code>语法块进行使用，<strong>它会在语法块结束时自动关闭文件</strong>。该函数：</p>
<pre><code class="python">open(file, mode=&quot;r&quot;, encoding=None)</code></pre>
<ul>
<li><code>file</code>是包含文件名的路径(传入基于当前目录的相对路径，传入或者绝对路径)，</li>
<li><code>mode</code> 参数是读写操作方式；</li>
<li><code>encoding</code> 是编码类型，一般取”utf8”。</li>
</ul>
<p>其中，读写操作方式常用的有：</p>
<table>
<thead>
<tr>
<th>参数</th>
<th>含义</th>
</tr>
</thead>
<tbody><tr>
<td>“r”</td>
<td>(默认)读。</td>
</tr>
<tr>
<td>“w”</td>
<td>写。该模式会覆盖原有内容；如文件不存在，会自动新建。</td>
</tr>
<tr>
<td>“x”</td>
<td>创建新文件并写入。</td>
</tr>
<tr>
<td>“a”</td>
<td>在已有文件的尾部追加。</td>
</tr>
</tbody></table>
<h3 id="8-1-一般读"><a href="#8-1-一般读" class="headerlink" title="8-1.一般读"></a>8-1.一般读</h3><p>函数 <code>read()</code> 将整个文件读为一个字符串，来看一个例子：</p>
<pre><code class="python">datapath = os.path.join(os.getcwd(), &quot;data&quot;, &quot;iris.data.csv&quot;)
with open(datapath, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:
    rawtext = f.read()

rawtext[:200]</code></pre>
<blockquote>
<p>结果：’5.1,3.5,1.4,0.2,Iris-setosa\n4.9,3.0,1.4,0.2,Iris-setosa\n4.7,3.2,1.3,0.2,Iris-setosa\n4.6,3.1,1.5,0.2,Iris-setosa\n5.0,3.6,1.4,0.2,Iris-setosa\n5.4,3.9,1.7,0.4,Iris-setosa\n4.6,3.4,1.4,0.3,Iris-setosa\n5.0,’</p>
</blockquote>
<p>函数 <code>readlines()</code> 将整个文件读为一个列表，文件的每一行对应列表的一个元素。</p>
<pre><code class="python">with open(datapath, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:
    rawtext = f.readlines()

rawtext[:3]</code></pre>
<blockquote>
<p>结果：<br>[‘5.1,3.5,1.4,0.2,Iris-setosa\n’,<br>     ‘4.9,3.0,1.4,0.2,Iris-setosa\n’,<br>     ‘4.7,3.2,1.3,0.2,Iris-setosa\n’]</p>
</blockquote>
<p>上述的 <code>readlines()</code> 函数实质等同于列表解析：</p>
<pre><code class="python">with open(datapath, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:
    rawtext = [line for line in f]

rawtext[:3]</code></pre>
<blockquote>
<p>结果：<br>    [‘5.1,3.5,1.4,0.2,Iris-setosa\n’,<br>     ‘4.9,3.0,1.4,0.2,Iris-setosa\n’,<br>     ‘4.7,3.2,1.3,0.2,Iris-setosa\n’]</p>
</blockquote>
<h3 id="8-2-一般写"><a href="#8-2-一般写" class="headerlink" title="8-2.一般写"></a>8-2.一般写</h3><p>文件写入，使用 <code>write()</code> 函数。一个简单的例子：</p>
<pre><code class="python">with open(datapath, &quot;w&quot;) as f:
   f.write(&quot;Sometimes naive.&quot;)</code></pre>
<h3 id="8-3-大文件读取"><a href="#8-3-大文件读取" class="headerlink" title="8-3.大文件读取"></a>8-3.大文件读取</h3><p>如果文件比较大，使用 <code>read()/readlines()</code> 函数直接读入可能会占用太多内存。推荐使用函数 <code>readline()</code>，一种迭代器式的读取方法。</p>
<pre><code class="python">with open(datapath, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:
    print(f.readline().strip())
    print(f.readline().strip())</code></pre>
<blockquote>
<p>结果:<br>    5.1,3.5,1.4,0.2,Iris-setosa<br>    4.9,3.0,1.4,0.2,Iris-setosa</p>
</blockquote>
<p>你会发现两次结果是不同的，这是因为迭代器内部的<strong>指针</strong>向后移动了。</p>
<p>怎样获取移动<strong>指针</strong>的位置呢？</p>
<blockquote>
<p>使用 <code>tell() / seek()</code> 命令</p>
</blockquote>
<pre><code class="python">with open(datapath, &quot;r&quot;, encoding=&quot;utf8&quot;) as f:
    print(f.tell(), f.readline().strip())
    print(f.tell(), f.readline().strip())
    f.seek(0)  # 回到文件头
    print(f.tell(), f.readline().strip())</code></pre>
<blockquote>
<p>结果:<br>    0 5.1,3.5,1.4,0.2,Iris-setosa<br>    28 4.9,3.0,1.4,0.2,Iris-setosa<br>    0 5.1,3.5,1.4,0.2,Iris-setosa</p>
</blockquote>
<h2 id="9-类"><a href="#9-类" class="headerlink" title="9.类"></a>9.类</h2><p>类的成员包括<strong>属性(attribute)</strong>与<strong>方法(method)</strong>两种。例子：</p>
<pre><code class="python">class MyClass:
    &quot;&quot;&quot;
    This is a class that can meow!
    &quot;&quot;&quot;
    animal = &quot;cat&quot;  # An attribute
    def talk(self):  # A method
        return &quot;Meow&quot; 

# An instance of the class
a = MyClass()
print(a.animal, a.talk())</code></pre>
<blockquote>
<p>结果:<br>    cat Meow</p>
</blockquote>
<p>上例中的 <code>self</code> 表示<strong>类的实例</strong>，所有类内部的方法都需要把该参数放在首位(你也不可不用<code>self</code>而使用<code>this</code>等，但是<code>self</code>是惯例)。<br>例如，<code>self.animal</code> 就表示了实例的 animal 属性。这与 C# 等语言中的<strong>this.animal</strong>是类似的。</p>
<p>下例证明了 <code>self</code> 代表的实质是类的实例，而不是类本身。</p>
<pre><code class="python">class EgClass:
    def __init__(self):
        print(self)  # 实例，有对应地址
        print(self.__class__)  # 类

a = EgClass()</code></pre>
<blockquote>
<p>结果:<br>    &lt;<strong>main</strong>.EgClass object at 0x000002531C0AF860&gt;<br>    &lt;class ‘<strong>main</strong>.EgClass’&gt;</p>
</blockquote>
<h3 id="9-1-构造函数"><a href="#9-1-构造函数" class="headerlink" title="9-1.构造函数"></a>9-1.构造函数</h3><p>类的构造函数是 <code>__init__()</code> (左右均为双下划线)，用于初始化实例。在声明实例时，该函数自动被调用。</p>
<pre><code class="python">class MyClass2:
    def __init__(self, animal=&quot;cat&quot;):
        self.animal = animal

a = MyClass2(&quot;dog&quot;)
a.animal</code></pre>
<blockquote>
<p>结果: ‘dog’</p>
</blockquote>
<h3 id="9-2-封装"><a href="#9-2-封装" class="headerlink" title="9-2.封装"></a>9-2.封装</h3><p>类的重要特性是封装性，即部分变量只能在其内部修改或访问，不能从类的外部进行处理。Python 中的封装非常简单，只要把<strong>属性</strong>或<strong>方法</strong>的名称前缀设置为<strong>双下划</strong>线即可。</p>
<p>由此可见，构造函数 <code>__init__()</code> 是最基本的一个私有方法。一个例子：</p>
<pre><code class="python">class MyClass3:
    def __init__(self, animal=&quot;cat&quot;):
        self.__animal = animal
        self.__foo()
    def __foo(self):
        self.__animal = &quot;rabbit&quot;
    def show(self):
        print(self.__animal)

a = MyClass3(&quot;dog&quot;)
a.show()</code></pre>
<blockquote>
<p>结果: rabbit</p>
</blockquote>
<p>如果想直接调用 <code>__foo()</code> 或者 <code>__animal</code>，都会被禁止，产生 <code>AttributeError</code>。</p>
<pre><code class="python"># a.__animal  # AttributeError</code></pre>
<p>要注意，<strong>前后均添加了双下划线</strong>的属性，如 <code>__name__</code> ，表示特殊属性而不是私有属性，是可以从外部访问的。</p>
<h3 id="9-3-继承"><a href="#9-3-继承" class="headerlink" title="9-3.继承"></a>9-3.继承</h3><p>类<code>Cat</code>与<code>Dog</code>都继承自<code>Animal</code>，同时也都重载了方法 talk()。</p>
<pre><code class="python">class Animal:
    def talk(self):
        pass # 表示定义留空

class Cat(Animal): # 从Animal 继承
    def talk(self): # 重写talk()
        print(&#39;Meow&#39;)

class Dog(Animal):
    def talk(self):
        print(&#39;Woof&#39;)

a, b = Cat(), Dog()
a.talk() # &#39;Meow&#39;
b.talk() # &#39;Woof&#39;</code></pre>
<blockquote>
<p>结果：<br>    Meow<br>    Woof</p>
</blockquote>
<p>通过 <code>isinstance()</code> 函数可以判断一个对象是否是某个类(或其子类)的实例：</p>
<pre><code class="python">print(isinstance(a, Cat), isinstance(a, Animal))</code></pre>
<blockquote>
<p>结果：True True</p>
</blockquote>
<p>或者：</p>
<pre><code class="python">type(a).__name__</code></pre>
<blockquote>
<p>结果：’Cat’</p>
</blockquote>
<p>当然，类也可以多继承。写在左侧的类的属性与方法，在继承时会被优先采用。例如：</p>
<pre><code class="python">class Pet:
    def talk(self):
        print(&quot;Pet&quot;)

class Cat2(Pet, Cat):
    pass

a = Cat2()
a.talk()</code></pre>
<blockquote>
<p>结果： Pet</p>
</blockquote>
<h3 id="9-4-property装饰器"><a href="#9-4-property装饰器" class="headerlink" title="9-4.@property装饰器"></a>9-4.@property装饰器</h3><p>装饰器 <code>@property</code> 可以被用于限制类属性的读写行为。比如，一个普通的类，如果想封装一个属性，却允许从外部读取它的值，一般我们用getter函数实现：</p>
<pre><code class="python">class Person:
    def __init__(self):
        self.__name = &quot;Py&quot;
    def get_name(self):
        return self.__name</code></pre>
<pre><code class="python">a = Person()
a.get_name()</code></pre>
<blockquote>
<p>结果：’Py’</p>
</blockquote>
<p>不得不说这实在是麻烦了，代码里一堆get函数满天飞并不令人愉快。而且还不能忘记它是一个函数，需要在尾部加上括号。</p>
<p>装饰器 <code>@property</code> 可以<strong>将一个方法伪装成同名的属性</strong>，因此装饰了getter函数后，调用时就不用加上尾部的括号了：</p>
<pre><code class="python">class Person:
    def __init__(self):
        self.__name = &quot;Py&quot;

    @property
    def name(self):
        return self.__name</code></pre>
<pre><code class="python">a = Person()
a.name</code></pre>
<blockquote>
<p>结果：’Py’</p>
</blockquote>
<p>而且，如果你想从外部修改该属性的值，会产生错误：</p>
<pre><code class="python">a.name = 1</code></pre>
<blockquote>
<p>结果：<br>   AttributeError: can’t set attribute</p>
</blockquote>
<p>但同时，我们也可以指定其setter函数(该装饰器 <code>@age.setter</code> 在用 <code>@property</code> 装饰 age 方法后会自动生成)，让属性修改成为可能，甚至附加修改条件：</p>
<pre><code class="python">class Person:
    def __init__(self):
        self.__age = 20

    @property
    def age(self):
        return self.__age

    @age.setter
    def age(self, value):
        if not isinstance(value, int):
            raise ValueError(&quot;Age should be an integer.&quot;)
        else:
            self.__age = value</code></pre>
<pre><code class="python">a = Person()
a.age = 30
a.age</code></pre>
<blockquote>
<p>结果：30</p>
</blockquote>
<p>不传入整数会报错：</p>
<pre><code class="python">a.age = 0.5</code></pre>
<blockquote>
<p>结果：<br>   ValueError: Age should be an integer.</p>
</blockquote>
<h3 id="9-5-类的特殊属性与方法"><a href="#9-5-类的特殊属性与方法" class="headerlink" title="9-5.类的特殊属性与方法"></a>9-5.类的特殊属性与方法</h3><h4 id="9-5-1-dict"><a href="#9-5-1-dict" class="headerlink" title="9-5-1.__dict__"></a>9-5-1.__dict__</h4><p>首先是 <code>__dict__</code> 属性，用于查看类的属性与方法，返回一个字典。</p>
<pre><code class="python">a = MyClass()
MyClass.__dict__</code></pre>
<blockquote>
<p>结果：<br>    mappingproxy({‘<strong>dict</strong>‘: &lt;attribute ‘<strong>dict</strong>‘ of ‘MyClass’ objects&gt;,<br>                  ‘<strong>doc</strong>‘: ‘\n    This is a class that can meow!\n    ‘,<br>                  ‘<strong>module</strong>‘: ‘<strong>main</strong>‘,<br>                  ‘<strong>weakref</strong>‘: &lt;attribute ‘<strong>weakref</strong>‘ of ‘MyClass’ objects&gt;,<br>                  ‘animal’: ‘cat’,<br>                  ‘talk’: <function __main__.MyClass.talk>})</p>
</blockquote>
<p>需要注意的是，此时实例 a 的属性没有被更改过，实例的 <code>__dict__</code> 是一个空字典：</p>
<pre><code class="python">print(a.__dict__, a.animal)</code></pre>
<blockquote>
<p>结果： {} cat</p>
</blockquote>
<p>类的 <code>__dict__</code> 方法下的同名键，与实例具有相同值。</p>
<pre><code class="python">MyClass.__dict__[&quot;animal&quot;]</code></pre>
<blockquote>
<p>结果: ‘cat’</p>
</blockquote>
<p>一旦被从外部更改，实例 a 的 <code>__dict__</code> 字典就不再为空。</p>
<pre><code class="python">a.animal = &quot;dog&quot;
print(a.__dict__, a.animal)</code></pre>
<blockquote>
<p>结果： {‘animal’: ‘dog’} dog</p>
</blockquote>
<h4 id="9-5-2-slots"><a href="#9-5-2-slots" class="headerlink" title="9-5-2.__slots__"></a>9-5-2.__slots__</h4><p>从上面可以看到，非私有的类属性可以从外部更改值，而且属性还能直接从外部增加。<code>__slots__</code> 属性的作用就在于使类的属性不能从外部进行更改、追加。<br>它能够限制属性滥用，并在优化内存上也有意义。</p>
<pre><code class="python">class MySlotClass():
    __slots__ = (&quot;meow&quot;, &quot;woof&quot;)
    def __init__(self):
        self.meow = &quot;Meow&quot;
        self.woof = &quot;Woof&quot;

a = MySlotClass()
MySlotClass.__dict__</code></pre>
<blockquote>
<p>结果：<br>mappingproxy({‘<strong>doc</strong>‘: None,<br>                  ‘<strong>init</strong>‘: <function __main__.MySlotClass.__init__>,<br>                  ‘<strong>module</strong>‘: ‘<strong>main</strong>‘,<br>                  ‘<strong>slots</strong>‘: (‘meow’, ‘woof’),<br>                  ‘meow’: &lt;member ‘meow’ of ‘MySlotClass’ objects&gt;,<br>                  ‘woof’: &lt;member ‘woof’ of ‘MySlotClass’ objects&gt;})</p>
</blockquote>
<p>此时，如果使用 <code>a.__dict__</code>，结果不会返回空字典，而是会报错。</p>
<h4 id="9-5-3-运算符重载"><a href="#9-5-3-运算符重载" class="headerlink" title="9-5-3.运算符重载"></a>9-5-3.运算符重载</h4><p>特别地，Python 提供了运算符重载的功能。常用的对应如下(参考 <a href="https://docs.python.org/3/library/operator.html" target="_blank" rel="noopener">官方页面</a>)：</p>
<table>
<thead>
<tr>
<th>方法</th>
<th>含义</th>
<th>应用</th>
</tr>
</thead>
<tbody><tr>
<td>一元运算符</td>
<td></td>
<td></td>
</tr>
<tr>
<td><code>__len__</code></td>
<td>长度</td>
<td>len(a)</td>
</tr>
<tr>
<td><code>__bool__</code></td>
<td>逻辑值</td>
<td>bool(a)</td>
</tr>
<tr>
<td><code>__neg__</code></td>
<td>取负值</td>
<td>-a</td>
</tr>
<tr>
<td><code>__str__ / __repr__</code></td>
<td>字符串形式</td>
<td>repr(a) / str(a), print(a)</td>
</tr>
<tr>
<td>二元运算符</td>
<td></td>
<td></td>
</tr>
<tr>
<td><code>__add__</code></td>
<td>加</td>
<td>a + b, a += b</td>
</tr>
<tr>
<td><code>__sub__</code></td>
<td>减</td>
<td>a - b, a -= b</td>
</tr>
<tr>
<td><code>__mul__</code></td>
<td>乘</td>
<td>a * b, a *= b</td>
</tr>
<tr>
<td><code>__div__</code></td>
<td>除</td>
<td>a / b, a /= b</td>
</tr>
<tr>
<td><code>__pow__</code></td>
<td>乘方</td>
<td>a ** b, a **= b</td>
</tr>
<tr>
<td><code>__radd__</code></td>
<td>左加</td>
<td>… + a</td>
</tr>
<tr>
<td>二元关系符</td>
<td></td>
<td></td>
</tr>
<tr>
<td><code>__lt__ / __le__</code></td>
<td>小于 / 小于等于</td>
<td>a &lt; b, a &lt;= b</td>
</tr>
<tr>
<td><code>__gt__ / __ge__</code></td>
<td>大于 / 大于等于</td>
<td>a &gt; b, a &gt;= b</td>
</tr>
<tr>
<td><code>__eq__ / __ne__</code></td>
<td>等于 / 不等于</td>
<td>a == b, a != b</td>
</tr>
</tbody></table>
<p>比如下例中，对多个运算进行了重载，完成了二维向量在加减法上与向量、与数运算的基本定义。</p>
<pre><code class="python">class Vector:
    def __init__(self, a, b):
        self.a = a
        self.b = b

    def __add__(self, another):
        if isinstance(another, Vector):
            c, d = another.a, another.b
        else:
            c, d = another, another
        return Vector(self.a + c, self.b + d)

    def __radd__(self, another):
        return self.__add__(another)

    def __neg__(self):
        return Vector(-self.a, -self.b)

    def __sub__(self, another):
        return self.__add__(-another)

    def __str__(self):
        return &quot;Vector({},{})&quot;.format(self.a, self.b)

v1 = Vector(0,3)
v2 = Vector(5,-2)
print(v1 - 1, -v2, v1 + v2, v1 - v2)</code></pre>
<blockquote>
<p>结果： Vector(-1,2) Vector(-5,2) Vector(5,1) Vector(-5,5)</p>
</blockquote>
<p>其中，<code>__repr__()</code> 与 <code>__str__()</code> 的主要区别在于，前者在交互式步骤中显示结果，后者在 print 函数中显示结果。</p>
<p>例如上例，如果直接输入 v1，不会以<strong>Vector(0,3)</strong>的形式显示。</p>
<pre><code class="python">v1  # 在类中附加定义： __repr__ = __str__ 即可解决问题。</code></pre>
<blockquote>
<p>结果： &lt;<strong>main</strong>.Vector at 0x2531c129c88&gt;</p>
</blockquote>
<h3 id="9-6-迭代行为"><a href="#9-6-迭代行为" class="headerlink" title="9-6.迭代行为"></a>9-6.迭代行为</h3><p>在类中也能定义迭代行为，需要 <code>__iter__()</code> 与 <code>__next__()</code> 方法。</p>
<pre><code class="python"># 该例改编自官方文档
class MyClass4:
    def __init__(self, lst):
        self.data = lst
        self.__index = len(lst)
    def __iter__(self):
        return self
    def __next__(self):
        if self.__index == 0:
            raise StopIteration
        self.__index -= 1
        return self.data[self.__index]

a = MyClass4(&quot;Meow&quot;)
for char in a:
    print(char)</code></pre>
<blockquote>
<p>结果：<br>    w<br>    o<br>    e<br>    M</p>
</blockquote>
<h2 id="10-常用模块"><a href="#10-常用模块" class="headerlink" title="10.常用模块"></a>10.常用模块</h2><p>下面介绍几个常用的 Python 标准模块(即随 Python 安装的模块)。更多的第三方模块，例如 NumPy, pandas, matplotlib，可以参考本系列博文的其他文章。</p>
<h3 id="10-1-os-模块"><a href="#10-1-os-模块" class="headerlink" title="10-1.os 模块"></a>10-1.os 模块</h3><p>这个模块应该是 Python 自带模块中使用率最高的一个了。一些例子：</p>
<pre><code class="python"># import os
#
# ----- 文件操作 -----
# os.rename(&quot;old.py&quot;, &quot;new.py&quot;)  # 重命名
# os.remove(&quot;a.py&quot;)  # 删除
# os.stat(&quot;b.py&quot;)  # 查看文件属性
#
# ----- 路径操作 -----
# os.getcwd()  # 获取当前目录
# os.chdir(r&quot;d:\list&quot;)  # 更改当前目录为
# os.chdir(os.pardir)  # 返回上一级目录
# os.mkdir(&#39;newfolder &#39;)  # 在当前目录新建一个文件夹
# os.listdir(&#39;c:\list&#39;)  # 列出文件夹下所有文件的列表
# os.removedirs(&#39;thefolder &#39;)  # 删除空文件夹
# os.path.isfile/ispath(&quot;f&quot;)  # 检查路径是文件或是目录
# os.path.exists(&quot;f&quot;)  # 检查路径是否存在
# 
# ----- 操作平台相关 -----
# os.sep  # 当前操作系统的路径分隔符
# os.linesep  # 当前操作系统的换行符
# os.path.join(r&quot;c:\abc&quot;, &quot;d&quot;)  # 连接字串成为路径</code></pre>
<h3 id="10-2-sys-模块"><a href="#10-2-sys-模块" class="headerlink" title="10-2.sys 模块"></a>10-2.sys 模块</h3><p>一般我很少用到这个模块。可能有这么几个命令会用到：</p>
<ul>
<li>sys.argv：能够传递从命令行接受的参数到代码内。</li>
<li>sys.platform：当前操作系统平台。</li>
<li>sys.exit()：无参数时抛出 SystemExit 错误并退出；有参数时会在退出前输出对应的字符串到屏幕。</li>
</ul>
<pre><code class="python">import sys
sys.platform</code></pre>
<blockquote>
<p>结果： ‘win32’</p>
</blockquote>
<pre><code class="Python">python test.py hello</code></pre>
<blockquote>
<p>此时，sys.argv[0] = test.py，sys.argv[1] = hello. </p>
</blockquote>
<h3 id="10-3-re模块"><a href="#10-3-re模块" class="headerlink" title="10-3.re模块"></a>10-3.re模块</h3><p>正则表达式的基础内容参考本博客的这篇博文：<a href="https://wklchris.github.io/Regular-Expression.html" target="_blank" rel="noopener">正则表达式</a>。<br>注意：如果要保存一个正则表达式供多次使用，<strong>请存储其compile后的结果</strong>，避免反复编译。</p>
<ul>
<li>re.compile(exp)：编译正则表达式。</li>
<li>re.compile(exp).match(str)：判断正则表达式能否匹配一个字串。可以 bool() 结果来获知是否匹配。<ul>
<li>re.compile(exp).match(str).groups()：将匹配结果返回为单个字符串(无子组时)或元组(有子组时)。</li>
<li>re.compile(exp).findall(str)：找出字符串中所有匹配表达式的子串。返回列表。</li>
</ul>
</li>
<li>re.split(exp, str)：用表达式来分割字符串，相当于 str.split() 的增强版。</li>
</ul>
<pre><code class="python">import re
bool(re.match(r&quot;\d&quot;, &quot;1&quot;))</code></pre>
<blockquote>
<p>结果：True</p>
</blockquote>
<pre><code class="python">phone_re = re.compile(r&#39;\d{3,4}-\d{7,8}&#39;)
phone_re.match(&#39;010-12345678&#39;).group()</code></pre>
<blockquote>
<p>结果：’010-12345678’</p>
</blockquote>
<pre><code class="python"># 如果在正则表达式中添加了子组(小括号)，那么会返回子组依顺序组成的一个元组
phone_re = re.compile(r&#39;(\d{3,4})-(\d{7,8})&#39;)
phone_re.match(&#39;010-12345678&#39;).groups()</code></pre>
<blockquote>
<p>结果：(‘010’, ‘12345678’)</p>
</blockquote>
<pre><code class="python">phone_re = re.compile(r&#39;\d{3,4}-\d{7,8}&#39;)  # 寻找所有子串
phone_set = &#39;010-12345678, 021-65439876 &#39;
phone_re.findall(phone_set)</code></pre>
<blockquote>
<p>结果：[‘010-12345678’, ‘021-65439876’]</p>
</blockquote>
<pre><code class="python">s = &#39;a b   c&#39;  # 用 re.split() 处理连续的空格
print(s.split(&#39; &#39;), re.split(r&quot;\s+&quot;, s))</code></pre>
<blockquote>
<p>结果： [‘a’, ‘b’, ‘’, ‘’, ‘c’] [‘a’, ‘b’, ‘c’]</p>
</blockquote>
<h3 id="10-4-其他模块"><a href="#10-4-其他模块" class="headerlink" title="10-4.其他模块"></a>10-4.其他模块</h3><ul>
<li>collection 模块：<ul>
<li>提供了一种双端列表 deque，可以用 appendleft, extendleft, popleft 等方法从 deque 的左侧(也就是lst[0])进行操作。注意，deque 的更新操作比 list 更快，但读取操作比 list 慢。</li>
<li>提供了一种缺省字典 defaultdict，可以直接操作键值(即使这个键先前未定义)；首次操作时会赋一个合理的初值，比如首次调用 <code>d[&quot;a&quot;] += 1</code> 而字典本身没有 “a” 键时，会自动初始化 “a” 键并赋初值 0。</li>
</ul>
</li>
<li>calendar 模块：判断星期、闰年，输出日历等等。</li>
<li>itertools 模块：在本文<strong>迭代器</strong>小节已进行了简要介绍。</li>
<li>logging 模块：在调试中可能会使用。</li>
<li>urllib 模块：这是一个HTML请求模块，常用于爬虫。</li>
</ul>
<h2 id="11-调试与测试"><a href="#11-调试与测试" class="headerlink" title="11.调试与测试"></a>11.调试与测试</h2><p>Python 中有一些内置的办法进行调试与测试。</p>
<h3 id="11-1-assert"><a href="#11-1-assert" class="headerlink" title="11-1.assert"></a>11-1.assert</h3><p>断言的含义在于，如果断言失败(False)，那么代码会被终止(抛出一个AssertionError)。比如：</p>
<pre><code class="python">n = 0
assert(n != 0)
1 / n</code></pre>
<p>与大家一贯喜欢使用的<code>print</code>调试法相比，断言语句可以用命令行参数 <code>-O</code> 忽略。这样所有的 <code>assert()</code> 语句都不会被执行。</p>
<pre><code class="cmd">$ python -O main.py</code></pre>
<h3 id="11-2-日志调试"><a href="#11-2-日志调试" class="headerlink" title="11-2.日志调试"></a>11-2.日志调试</h3><p>logging 模块支持将错误日志输出(到控制台或者到文件)。</p>
<p>此乃调试神器。延伸阅读：<a href="https://docs.python.org/3/howto/logging.html#logging-basic-tutorial" target="_blank" rel="noopener">logging 官方基础教程</a>。</p>
<pre><code class="python">import logging
# 该行也可能通过控制台：$ python main.py --log=WARNING 的方式实现
logging.basicConfig(level=logging.WARNING)</code></pre>
<pre><code class="python">n = 0
logging.warning(&quot;n = {}&quot;.format(n))</code></pre>
<blockquote>
<p>结果： WARNING:root:n = 0</p>
</blockquote>
<p>logging 模块的灵活之处在于你可以记录信息的级别(DEBUG，INFO，WARNING，ERROR，CRITICAL)，各级别的作用如下：</p>
<ul>
<li>DEBUG：最详细的级别，所有详细日志都会被输出。</li>
<li>INFO：检测代码是否按照预期执行。</li>
<li>WARNING：非预期的事件发生了，或者可能在近期发生(例如：低磁盘空间)。但代码仍然执行。</li>
<li>ERROR：发生了级别更高的问题，某些功能无法正常实现。</li>
<li>CRITICAL：严重错误，代码可能无法继续运行。</li>
</ul>
<p>通过 <code>filename</code> 参数，可以将日志写入到文件。一般使用 DEBUG 级别，即输出所有信息。</p>
<pre><code class="python">logging.basicConfig(filename=&quot;log.log&quot;, level=logging.DEBUG)</code></pre>
<p>默认会将日志追加到文件末尾，如果想要覆写文件而不是追加，使用 <code>filemode</code> 参数：</p>
<pre><code class="python">logging.basicConfig(filename=&quot;log.log&quot;, filemode=&quot;w&quot;, level=logging.DEBUG)</code></pre>
<p>更改日志格格式，使用 <code>format</code> 参数。一般来说，常用的格式码(格式码后加 s 表示字符串)有：</p>
<ul>
<li><code>%(levelname)</code>：当前日志字串级别。</li>
<li><code>%(message)</code>：当前日志字串。</li>
<li><code>%(asctime)</code>：当前时间。默认 datefmt 参数为 <code>%Y-%m-%d %I:%M:%S</code></li>
</ul>
<p>例子。下例会输出形如：”01/23/1900 08:05:05 PM is when this event was logged.” 这样的格式。</p>
<pre><code class="python">logging.basicConfig(format=&#39;%(asctime)s %(message)s&#39;, datefmt=&#39;%m/%d/%Y %I:%M:%S %p&#39;)
# logging.warning(&#39;is when this event was logged.&#39;)</code></pre>
<pre><code class="python"># 常用的格式：
logging.basicConfig(format=&quot;%(levelname)s: %(message)s&quot;)</code></pre>
<p>还可以通过配置文件来代替 basicConfig 命令，并进行设置 logger 等更高级的配置。<br>这部分可以参考：<a href="https://docs.python.org/3/library/logging.config.html#configuration-file-format" target="_blank" rel="noopener">此处</a>。</p>
<pre><code class="python">import logging.config

logging.config.fileConfig(&#39;logging.conf&#39;)</code></pre>
<h2 id="12-练习"><a href="#12-练习" class="headerlink" title="12.练习"></a>12.练习</h2><h3 id="12-1-列表、字典解析"><a href="#12-1-列表、字典解析" class="headerlink" title="12-1.列表、字典解析"></a>12-1.列表、字典解析</h3><ul>
<li>列表解析时注意<strong>嵌套的顺序</strong>。下例中，i 是外层循环，j 是内层循环。</li>
<li>循环变量不被使用时，可以<strong>用单下划线代替</strong>（不仅在解析中，在循环体中也可以这样）。</li>
</ul>
<pre><code class="python">[&quot;{}-{}&quot;.format(i, j) for i in range(5) if i % 2 == 0
                      for j in range(3)]

# 调换顺序，会得到不同的结果：
[&quot;{}-{}&quot;.format(i, j) for j in range(3)
                      for i in range(5) if i % 2 == 0]</code></pre>
<blockquote>
<p>结果：<br>[‘0-0’, ‘0-1’, ‘0-2’, ‘2-0’, ‘2-1’, ‘2-2’, ‘4-0’, ‘4-1’, ‘4-2’]<br>[‘0-0’, ‘2-0’, ‘4-0’, ‘0-1’, ‘2-1’, ‘4-1’, ‘0-2’, ‘2-2’, ‘4-2’]</p>
</blockquote>
<p>用单下划线代替的解析：</p>
<pre><code class="python">[&quot;a&quot; for _ in range(5)]  # 等同于 [&quot;a&quot;] * 5</code></pre>
<blockquote>
<p>结果： [‘a’, ‘a’, ‘a’, ‘a’, ‘a’]</p>
</blockquote>
<p>字典解析：</p>
<pre><code class="python">{i: i ** 2 for i in range(5)}</code></pre>
<blockquote>
<p>结果： {0: 0, 1: 1, 2: 4, 3: 9, 4: 16}</p>
</blockquote>
<h3 id="12-2-collections使用"><a href="#12-2-collections使用" class="headerlink" title="12-2.collections使用"></a>12-2.collections使用</h3><p>该模块主要提供了一些实用的方法。</p>
<h4 id="12-2-1-示例"><a href="#12-2-1-示例" class="headerlink" title="12-2-1.示例"></a>12-2-1.示例</h4><p>函数 namedtuple 可以构造一个类——它只有少量属性，没有方法。在声明实例时，属性将作为构造函数的参数传入。</p>
<pre><code class="python">import collections
Poker = collections.namedtuple(&quot;Poker&quot;, [&quot;suit&quot;, &quot;number&quot;])

a = Poker(&quot;Club&quot;, &quot;9&quot;)  # 梅花9

a
a.suit
a.number</code></pre>
<blockquote>
<p>结果：<br>    Poker(suit=’Club’, number=’9’)<br>    ‘Club’<br>    ‘9’</p>
</blockquote>
<p>值得注意的是，一个 Poker 类的实例被视为一个元组对象。函数名<code>namedtuple</code>也暗示了这一点。</p>
<pre><code class="python">isinstance(a, tuple)</code></pre>
<blockquote>
<p>结果： True</p>
</blockquote>
<h4 id="12-2-2-扑克牌"><a href="#12-2-2-扑克牌" class="headerlink" title="12-2-2.扑克牌"></a>12-2-2.扑克牌</h4><p>扑克牌不算大小王有 52 张，怎样表示这样的一副牌呢？我们可以创建一个新类 FPoker，并定义：</p>
<ul>
<li>【属性】在其内部存储一个私有列表 <code>_poker</code>，记录 52 张牌。每个元素是一个 Poker 对象。</li>
<li>【方法】长度 <code>__len__</code>，取值 <code>__getitem__</code> ……</li>
</ul>
<pre><code class="python">class FPoker():
    &quot;&quot;&quot;
    A class of French suits poker including 52 cards.

    Attr:
        numbers: List of card values from low to high.
        suits: List of card suits from low to high.
    &quot;&quot;&quot;
    _n = [str(i) for i in range(3, 11)] + list(&quot;JQKA2&quot;)
    _s = &quot;Diamonds Clubs Hearts Spades&quot;.split()

    def __init__(self):
        self._poker = [Poker(suit, number) for suit in self._s 
                                           for number in self._n]

    @property
    def numbers(self):
        return self._n

    @property
    def suits(self):
        return self._s

    def __len__(self):
        return len(self._poker)

    def __getitem__(self, i):
        return self._poker[i]</code></pre>
<pre><code class="python">a = FPoker()
a.numbers  # 点数顺序
a[0]  # 最小的牌</code></pre>
<blockquote>
<p>结果<br>[‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘10’, ‘J’, ‘Q’, ‘K’, ‘A’, ‘2’]<br>Poker(suit=’Diamonds’, number=’3’)</p>
</blockquote>

      
       <hr><span style="font-style: italic;color: gray;"> 转载请注明来源，欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论，也可以邮件至 pgmanor@qq.com </span>
    </div>
</article>


<p>
    <a  class="dashang" onclick="dashangToggle()">赏</a>
</p>


<div class="article_copyright">
    <p><span class="copy-title">文章标题:</span>python基本语法</p>
    <p><span class="copy-title">字数:</span><span class="post-count">9.8k</span></p>
    <p><span class="copy-title">本文作者:</span><a  title="pgmanor">pgmanor</a></p>
    <p><span class="copy-title">发布时间:</span>2020-12-31, 00:00:00</p>
    <p><span class="copy-title">最后更新:</span>2020-12-15, 23:12:30</p>
    <span class="copy-title">原始链接:</span><a class="post-url" href="/blog/2020/12/31/blog-python_base/" title="python基本语法">https://pgmanor.gitee.io/blog/2020/12/31/blog-python_base/</a>
    <p>
        <span class="copy-title">版权声明:</span><i class="fa fa-creative-commons"></i> <a rel="license noopener" href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank" title="CC BY-NC-SA 4.0 International" target = "_blank">&#34;署名-非商用-相同方式共享 4.0&#34;</a> 转载请保留原文链接及作者。
    </p>
</div>



    <div id="comments"></div>

<script src="/blog/js/valine.min.js"></script>

<script type="text/javascript">
    new Valine({
        el: '#comments',
        appId: 'g5VDso59rLvb68pq56BNnQ7A-gzGzoHsz',
        appKey: '2bebBs4aVT95Btj4j9zJve2O',
        placeholder: '说点什么...',
        avatar: 'monsterid',
        visitor : 'false'
    })
</script>




    




    </div>
    <div class="copyright">
        <p class="footer-entry">©2021 pgmanor</p>
<!--<p class="footer-entry">Built with <a href="https://hexo.io/" target="_blank">Hexo</a> and <a href="https://github.com/yelog/hexo-theme-3-hexo" target="_blank">3-hexo</a> theme</p>-->

    </div>
    <div class="full-toc">
        <button class="full" data-title="切换全屏 快捷键 s"><span class="min "></span></button>
<button class="post-toc-menu" data-title="打开TOC 快捷键 w"><span class="post-toc-menu-icons"></span></button>
<div class="post-toc"><span class="post-toc-title">目录</span>
    <div class="post-toc-content">

    </div>
</div>
<a class="" id="rocket" ></a>

    </div>
</div>
<div class="acParent"></div>

<div class="hide_box" onclick="dashangToggle()"></div>
<div class="shang_box">
    <a class="shang_close"  onclick="dashangToggle()">×</a>
    <div class="shang_tit">
        <p>喜欢就点赞,疼爱就打赏</p>
    </div>
    <div class="shang_payimg">
        <div class="pay_img">
            <img src="/blog/img/alipay.jpg" class="alipay" title="扫码支持">
            <img src="/blog/img/weixin.jpg" class="weixin" title="扫码支持">
        </div>
    </div>
    <div class="shang_payselect">
        <span><label><input type="radio" name="pay" checked value="alipay">支付宝</label></span><span><label><input type="radio" name="pay" value="weixin">微信</label></span>
    </div>
</div>


</body>
<script src="/blog/js/jquery.pjax.js?v=1.0.1x" ></script>

<script src="/blog/js/script.js?v=1.0.1x" ></script>
<script>
    var img_resize = 'default';
    /*作者、标签的自动补全*/
    $(function () {
        $('.search').AutoComplete({
            'data': ['@pgmanor','#AQS','#attr','#aysnc','#beanmap','#bigdecimal','#blog','#chrome','#dict','#dll','#doc','#docker','#domain','#elementadmin','#es','#excel','#farm','#fastjson','#func','#git','#github','#guide','#hadoop','#hexo','#idea','#initialzr','#jackson','#java','#jboss','#jdni','#jetbrains','#jfinalshell','#joplin','#JPA','#junit','#jupyter','#keepavlie','#kill','#linux','#LocalDate','#lock','#markdown','#maven','#message','#mock','#mq','#mycat','#mysql','#nginx','#notebook','#postman','#powermock','#python','#redis','#rest','#sharding-jdbc','#spark','#springboot','#testng','#tornado','#track','#transactional','#uuid','#vuepress','#web','#windows','#zookeeper','#分库分表','#分页','#加密','#启动','#工具','#并发','#序列化','#微服务','#性能分析','#手册','#有道云','#模板','#百度云盘','#算法','#面试','#项目',],
            'itemHeight': 20,
            'width': 418
        }).AutoComplete('show');
    })
    function initArticle() {
        /*渲染对应的表格样式*/
        
            $(".post .pjax table").addClass("green_title");
        

        /*渲染打赏样式*/
        
        $("input[name=pay]").on("click", function () {
            if($("input[name=pay]:checked").val()=="weixin"){
                $(".shang_box .shang_payimg .pay_img").addClass("weixin_img");
            } else {
                $(".shang_box .shang_payimg .pay_img").removeClass("weixin_img");
            }
        })
        

        /*高亮代码块行号*/
        
        $('pre code').each(function(){
            var lines = $(this).text().trim().split('\n').length, widther='';
            if (lines>99) {
                widther = 'widther'
            }
            var $numbering = $('<ul/>').addClass('pre-numbering ' + widther).attr("unselectable","on");
            $(this).addClass('has-numbering ' + widther)
                    .parent()
                    .append($numbering);
            for(var i=1;i<=lines;i++){
                $numbering.append($('<li/>').text(i));
            }
        });
        

        /*访问数量*/
        
        $.getScript("//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js");
        

        /*代码高亮，行号对齐*/
        $('.pre-numbering').css('line-height',$('.has-numbering').css('line-height'));

        
        
    }

    /*打赏页面隐藏与展示*/
    
    function dashangToggle() {
        $(".shang_box").fadeToggle();
        $(".hide_box").fadeToggle();
    }
    

</script>

<!--加入行号的高亮代码块样式-->

<style>
    pre{
        position: relative;
        margin-bottom: 24px;
        border-radius: 10px;
        border: 1px solid #e2dede;
        background: #FFF;
        overflow: hidden;
    }
    code.has-numbering{
        margin-left: 30px;
    }
    code.has-numbering.widther{
        margin-left: 35px;
    }
    .pre-numbering{
        margin: 0px;
        position: absolute;
        top: 0;
        left: 0;
        width: 20px;
        padding: 0.5em 3px 0.7em 5px;
        border-right: 1px solid #C3CCD0;
        text-align: right;
        color: #AAA;
        background-color: #fafafa;
    }
    .pre-numbering.widther {
        width: 35px;
    }
</style>

<!--自定义样式设置-->
<style>
    
    
    .nav {
        width: 442px;
    }
    .nav.fullscreen {
        margin-left: -442px;
    }
    .nav-left {
        width: 120px;
    }
    
    
    @media screen and (max-width: 1468px) {
        .nav {
            width: 442px;
        }
        .nav.fullscreen {
            margin-left: -442px;
        }
        .nav-left {
            width: 150px;
        }
    }
    
    
    @media screen and (max-width: 1024px) {
        .nav {
            width: 442px;
            margin-left: -442px
        }
        .nav.fullscreen {
            margin-left: 0;
        }
        .nav .hide-list.fullscreen {
            left: 442px
        }
    }
    
    @media screen and (max-width: 426px) {
        .nav {
            width: 100%;
        }
        .nav-left {
            width: 100%;
        }
    }
    
    
    .nav-right .title-list nav a .post-title, .nav-right .title-list #local-search-result a .post-title {
        color: #383636;
    }
    
    
    .nav-right .title-list nav a .post-date, .nav-right .title-list #local-search-result a .post-date {
        color: #5e5e5f;
    }
    
    
    .nav-right nav a.hover, #local-search-result a.hover{
        background-color: #e2e0e0;
    }
    
    

    /*列表样式*/
    
    .post .pjax article .article-entry>ol, .post .pjax article .article-entry>ul, .post .pjax article>ol, .post .pjax article>ul{
        border: #e2dede solid 1px;
        border-radius: 10px;
        padding: 10px 32px 10px 56px;
    }
    .post .pjax article .article-entry li>ol, .post .pjax article .article-entry li>ul,.post .pjax article li>ol, .post .pjax article li>ul{
        padding-top: 5px;
        padding-bottom: 5px;
    }
    .post .pjax article .article-entry>ol>li, .post .pjax article .article-entry>ul>li,.post .pjax article>ol>li, .post .pjax article>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    .post .pjax article .article-entry li>ol>li, .post .pjax article .article-entry li>ul>li,.post .pjax article li>ol>li, .post .pjax article li>ul>li{
        margin-bottom: auto;
        margin-left: auto;
    }
    

    /* 背景图样式 */
    
    


    /*引用块样式*/
    

    /*文章列表背景图*/
    

    
</style>






<div class="mobile-menus-out" >

</div>
<div class="mobile-menus">
    
    
    
    <a class="dynamic-menu " target="_blank"  href="https://www.iworkh.com/">iworkh</a>
    
    
    <a class="dynamic-menu " target="_blank"  href="https://gitee.com/pgmanor">gitee</a>
    
</div>


<div style="position:absolute; bottom: 0; right: 0;">
    <iframe frameborder="no" border="0" marginwidth="0" marginheight="0" width=150 height=40 src="//music.163.com/outchain/player?type=2&id=1323150930&auto=0&height=32"></iframe>
</div>

</html>
